File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Access superclass variable using super" Watch "Access superclass variable using super" New topic

Access superclass variable using super

Mayuri Son

Joined: Oct 31, 2002
Posts: 4
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="" target="_blank" rel="nofollow">Try my mock exam.</a>
Mayuri Son

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.
I agree. Here's the link:
subject: Access superclass variable using super
jQuery in Action, 3rd edition