This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Access superclass variable using super

 
Mayuri Son
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 279
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
post the code snippet if you can
 
Dan Chisholm
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this.
 
Mayuri Son
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic