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/

7th May 2019, 9:48 AM
mohan borkar
mohan borkar - avatar
9 ответов
+ 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.
7th May 2019, 1:33 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 1
That means cat and dog types (lower type) are getting converted in to animal type (higher type), in this assignment. Thanks a lot.
7th May 2019, 12:50 PM
mohan borkar
mohan borkar - avatar
7th May 2019, 10:22 AM
mohan borkar
mohan borkar - avatar
0
O. K. agreed but why? To save memory and enhace performance? Please answer.
7th May 2019, 1:56 PM
mohan borkar
mohan borkar - avatar
0
O. K. I did not think about this reason. Thanks a lot.
7th May 2019, 5:13 PM
mohan borkar
mohan borkar - avatar