K
K
krembrule20162018-10-03 19:31:23
Java
krembrule2016, 2018-10-03 19:31:23

Is it possible to pass constants to the class constructor?

I want to pass a named constant to the class constructor
We have a class

package Bigshot.Characters;
public class CharacterCreationThree extends Thread{
MyCharacters[] array;
public enum Character{
   PlayerHero, Enemy
 }
 public void run(){
 //* MyCharacters[] array = new MyCharacters[complexity*5];
  for(int count=0; count<array.length;count++){
   System.out.println(count);
  <b> array[count] = new MyCharacters(Character.Enemy);</b>
   System.out.println("bot!");
  }
 }
}

We have a class MyCharacters
package Bigshot.Characters;
public class MyCharacters{
 Character CharacterType;//тип персонажа
 
  public MyCharacters(Character CharacterType){
   this.CharacterType = Character.CharacterType;
  }
  public void demonstrationOfHero(){
    
   System.out.println("Character created!");
  }
 
}

I cut out the excess in order to show the essence of the issue as best as possible :)
And as you might guess, it doesn’t fuss

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2018-10-03
@krembrule2016

public class MyCharacters {
  Character characterType;
 
  public MyCharacters(Character characterType) {
    this.characterType = characterType;
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question