| 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.
|
 |
 |
|
|
subject: Access superclass variable using super
|
|
|