0

is there a way I can use a variable as the name for my constructor? Without knowing the name the user will put in beforehand, etc.

String StuName = scanner.next();

Student StuName = new Student();

I'm really new and I'm trying to learn so I apologise if this is a stupid ass question.

  • you may wanna have a look at factory pattern. it is the solution for this type of problem – Mox Aug 18 '16 at 03:25
  • `"is there a way I can use a variable as the name for my constructor?"` -- this statement really doesn't make sense. The constructor "name" is the same as the name of the class. If you need to pass a String into the constructor, then give it a String parameter, and use the parameter to set a field, as is well demonstrated in most any tutorial on constructors. – Hovercraft Full Of Eels Aug 18 '16 at 03:41

0 Answers0