• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

super for instance variables

 
Malatesh Karabisti
Ranch Hand
Posts: 153
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Output :MyCountry

can any body please explain the result ?
 
Arjun Srivastava
Ranch Hand
Posts: 432
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Malatesh Karabisti wrote:

Output :MyCountry

can any body please explain the result ?

we use super keyword to access the methods or instance variables of super class or calling super class constructor in base class constructor.
here even at line 11 if you remove super output will be the same ,
as base class has already inherit the instance variable country.
at line 11,you can also try new TEST_1.country;
it will again give you the same output.
 
Malatesh Karabisti
Ranch Hand
Posts: 153
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Arjun!

I could understand the concept, I had in mind that we will use the "super" keyword only for overridden member. I think that is "wrong" we can use super keyword for all the members of the super class. that seems to be the rule.

Java Gurus.. If I am wrong please correct me
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic