File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes calling non-static from 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 "calling non-static from static context" Watch "calling non-static from static context" New topic

calling non-static from static context

marsha bianco

Joined: Aug 30, 2010
Posts: 4
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?
Dieter Quickfend

Joined: Aug 06, 2010
Posts: 543

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?

Oracle Certified Professional: Java SE 6 Programmer && Oracle Certified Expert: (JEE 6 Web Component Developer && JEE 6 EJB Developer)
Rob Spoor

Joined: Oct 27, 2005
Posts: 20276

Not GUI related; moving to Beginning Java.

How To Ask Questions How To Answer Questions
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

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 fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
I agree. Here's the link:
subject: calling non-static from static context
It's not a secret anymore!