We know how to create an instance by writing in the main…
Class newObject = new Class();
Is there a way to create a ‘newObject’ by user’s input something and pops a new newObject? I was thinking using the Scanner but i am not sure how it could be done. I was guessing like this:
Scanner sc = new Scanner(System.in);
Class sc.next(); = new Class();
or like this?
Scanner sc = new Scanner(System.in);
(some name) = sc.next();
Class (some name) = new Class();
So the user inputs an object name (some name) into the scanner and that object name (some name) will be created.
Thank you very much in advance!
The best way would be to make a constructor that takes in a Scanner class to create Class, given that you have access to the Class code and can put in the value.
If Class is a primitive, then you could just use the nextInt (Or other related) type functions.