It's not a secret anymore!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Polymorphism applies to instance methods not instance variables? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Polymorphism applies to instance methods not instance variables?" Watch "Polymorphism applies to instance methods not instance variables?" New topic
Author

Polymorphism applies to instance methods not instance variables?

Prithvi Sehgal
Ranch Hand

Joined: Oct 13, 2009
Posts: 774
Hello All,

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

Thanks,


Prithvi,
My Blog, Follow me on Twitter,Scjp Tips, When you score low in mocks, Generics,Scjp Notes, JavaStudyGroup
Neha Daga
Ranch Hand

Joined: Oct 30, 2009
Posts: 504
yup


SCJP 1.6 96%
Harpreet Singh janda
Ranch Hand

Joined: Jan 14, 2010
Posts: 317

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

Joined: Feb 21, 2010
Posts: 13
Yes. your assumption is right. please read 2nd chapter from K & B book for more details...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Polymorphism applies to instance methods not instance variables?
 
Similar Threads
Having confusion with variable override and method override
public Class variables and inheritance
INSTANCE VARIABLES
Question from Exam lab practice Exam 1 about polymorphism
Casting Doubt