aspose file tools*
The moose likes Beginning Java and the fly likes non-static variable super cannot be referenced from a static context Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "non-static variable super cannot be referenced from a static context" Watch "non-static variable super cannot be referenced from a static context" New topic
Author

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

Siva kandasamy
Ranch Hand

Joined: Dec 31, 2002
Posts: 139
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

Joined: Oct 29, 2001
Posts: 8866
    
    8

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.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: non-static variable super cannot be referenced from a static context