• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic