Answer the question
In order to leave comments, you need to log in
How to programmatically name an instance of a class?
I'm learning Java, I ran into such a problem, you need to enter the player's name, and based on this name a new object of the Player class is created, but I realized that I can't and don't know how to do it. And how without it to create other objects, the number of which will be different?
public void gameStart() {
String name;
Scanner input = new Scanner(System.in);
System.out.println("Input your player name:");
name = input.next();
System.out.println("You name now: " + name);
... here I wanted to create an object, but I realized that I can't
}
Team ivan = new Team("Ivan");
Answer the question
In order to leave comments, you need to log in
Use, for example List :
and add your players there:list.add(new Player(name) );
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question