wood burning stoves*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Access superclass variable using super Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Access superclass variable using super" Watch "Access superclass variable using super" New topic
Author

Access superclass variable using super

Mayuri Son
Greenhorn

Joined: Oct 31, 2002
Posts: 4
Hi,
Can we access superclass variable of the same name as one in the subclass using keyword super?
Let me explain clearly. If I have a superclass and there is a variable, with identifier i. Now if "subclass" extends "superclass" and has a variable named i. So is it possible to access superclass variable i using super.i (As we were doing in C++)
I have a book, it says "super is used to refer to the members of superclass, both data attributes
and methods"
But when I tried in a java program and it gives me errors
Thanks in advance
Alfred Kemety
Ranch Hand

Joined: Aug 14, 2002
Posts: 279
post the code snippet if you can


Alfred Raouf - Egypt - SCJP 1.4<br />Kemety.equals(Egyptian) // returns true
Dan Chisholm
Ranch Hand

Joined: Jul 02, 2002
Posts: 1865
Try this.


Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
Mayuri Son
Greenhorn

Joined: Oct 31, 2002
Posts: 4
Oops, I am sorry, Yesterday I was trying this but dont know why I was getting errors, But now working fine as per Dan's example. Sorry again!
Thanks Dan for the example.
 
Don't get me started about those stupid light bulbs.
 
subject: Access superclass variable using super