This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
thejaka wrote:How that the m.makeNoise()output not becomes "generic noise"?
polymorphism is ONLY for instance methods. At runtime it is the 'overriding' method in the object's 'TYPE' that is invoked. In line 12 of the program: the object's 'TYPE' is Zebra, hence the overriding makeNoise() method in the class Zebra is invoked.
I hope this helps.
In Your Pursuit Towards Certification, NEVER Give Up.
now if you say - it will pick the instance variable value from Mammal class (since name variable do not get overridden).
but when you write - it will display the output from the method, object does belong to. here in this case it is from Zebra class. (method is overridden in Zebra class).