0
Java Polymorphism Lesson: In this code explanation it is not clear, when it comes to word REFERENCE.
Does the word "reference" mean that the address is getting stored? OR it is like parent class's default constructor is also getting invoked along with child class's default constructor. OR both? Someone please explain it to me with reference to this code. https://www.sololearn.com/learn/Java/2164/
9 odpowiedzi
+ 14
When you create an object from a class, Java allocates the amount of memory the object requires to store the object.
Then, if you assign the object to a variable, the variable is actually assigned a 'reference' to the object, not the object itself.
This reference is the address of the memory location where the object is stored.
+ 1
That means cat and dog types (lower type) are getting converted in to animal type (higher type), in this assignment. Thanks a lot.
0
O. K. agreed but why? To save memory and enhace performance? Please answer.
0
O. K. I did not think about this reason. Thanks a lot.