1
Answer

Classes "Dog dog = new Dog();" what dose this acctualy do?

Mazetar

Mazetar

13y
1.9k
1
For the example Dog is an class.
I have been wondering about the following lines of code:

Dog dog = new Dog();

in comparance to this code:

Dog dog;
dog = new Dog();

I'm not sure if I have understood all what I have read inn the books and articles I'm learning from but the
Dog dog;
is the same as declearing a variable like an int "int myInt;" it only creates a space inn memory to store such int,
or inn the case of the dog it creates a place to store a Dog instance and lables it "dog" so you can refer to that place as dog?

so when you do
dog = new Dog();
you actually give the dog the information of Dog?
can you only set it as new Dog or could I set it as a new of another class than dog?
Answers (1)