Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Polymorphism applies to instance methods not instance variables?

 
Prithvi Sehgal
Ranch Hand
Posts: 774
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

Is my assumption correct that, polymorphism applies to instance methods only. Not instance variables?

Thanks,
 
Neha Daga
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yup
 
Harpreet Singh janda
Ranch Hand
Posts: 317
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you are right. for example in below example



output is


because at runtime method of subclass will be called but the member of parent is printed.
 
Abhishek Sawant
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. your assumption is right. please read 2nd chapter from K & B book for more details...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic