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).