This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

non-static variable super cannot be referenced from a static context

 
Siva kandasamy
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,
Look at the code and error text below. I have trouble in using keyword super, rest seems to be working well.
Do you see any reason, why I can't use keyword super to access method "tune", but I am able to use parent class "Instrument". ie "Instrument.tune(flute);"
Let me know, if you have any questions ?
thanks
siva



javac Wind.java
Wind.java:24: non-static variable super cannot be referenced from a static context
super.tune(flute); // Upcasting (EE)
^
1 error
 
Joe Ess
Bartender
Posts: 9256
9
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sivanantham kandan:

Do you see any reason, why I can't use keyword super to access method "tune", but I am able to use parent class "Instrument". ie "Instrument.tune(flute);"

You can call Instrument.tune because that method is static. You don't need an instance of Instrument to call it. The super handle you are trying to use is an instance variable in an Object which refers to its superclass. Without an instance of, say Wind, you cannot use its member variable super.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic