• 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

calling non-static from static context

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, I am developing an app for school. I have an abstract super entitled Student, and three concrete public subs called Undergraduate, Graduate, and PartTime. All of these are in separate files, but are in the same package. In the super, I have multiple abstract methods such as add();. In the subs, I implement them with public void add() {...method body...}. Then I am using a GUI as a driver app, also a separate file. I am trying to call the method add(sID, fName, lName, sGpa, sStatus, sMentor, cHours, sLevel) {..}, but the system won't recognize the symbol because the constructor in the super and subs have no params: add() {}. If I put params in the sub method, it won't override the method from the super. Each sub adds one or two params to the super, and that is why I cannot use the same for all. The subs are supposed to implement, and the GUI calls upon an actionperformed. I could use only Undergraduate.add() in the actionperformed, but then I get the "cannot call non-static from static" error. Any ideas?
 
Bartender
Posts: 543
4
Netbeans IDE Redhat Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't really make up much from your whole post, but if this is just an overriding problem, why don't you go add(Object... ob) in your super, and override that in your subs?

Perhaps post a code snippet to make things clearer?
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not GUI related; moving to Beginning Java.
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all welcome to the JavaRanch.

If you define that Student has a method add() with no arguments then you can't override it with a method add that does have arguments.
 
Any sufficiently advanced technology will be used as a cat toy. And this tiny ad contains a very small cat:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic