• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question in scjp study guide (Kathey & Bates) page 181- oo Concepts

 
thejaka samarakoon
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


In this question Why the out put display as
furry bray?
How that the m.makeNoise()output not becomes "generic noise"?
 
Ikpefua Jacob-Obinyan
Ranch Hand
Posts: 394
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thejaka wrote:How that the m.makeNoise()output not becomes "generic noise"?

Hello thejaka,
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.

Regards

Ikpefua
 
thejaka samarakoon
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.
 
shalindra Singh Suryvanshee
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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

Thanks
Shalindra
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic