I'm new to java, and am having trouble getting my head around the concept of dynamically creating objects. I understand that objects are created at runtime, and have seen methods of dynamic creation using arrays, but this seems a bit convoluted, and I can only assume I am not doing things the 'java way'.
For example, if I have a class Dog:
public class Dog {
int age;
public void setAge(int age){
this.age = age;
}
}
and i want to create a new dog and set its age:
dog newDog = new dog();
newDog.setAge(3);
Then there is no problem. However, if I want to take user input where I take the dogs name and use that name as the name of the object itself, then I hit a bit of a brick wall. I envisaged something along the lines of:
Scanner sc = new Scanner(System.in);
dog sc.Next() = new dog();
furthermore, not knowing the name of the newly created object ahead of time seemingly makes it impossible to reference it (e.g. for a setter method).
As I said, I am convinced that my brain is just not thinking in java. I'm more used to programming in a linear fashion with vba or python, and I think OOP has my head spinning in circles. Any resources that anyone could point me to that might help me see the wood for the trees would be much appreciated. I've scoured the web in an effort to find something with no success thus far.