| Author |
calling non-static from static context
|
marsha bianco
Greenhorn
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
Ranch Hand
Joined: Aug 06, 2010
Posts: 280
|
|
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 Programmer
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
Not GUI related; moving to Beginning Java.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
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.
|
 |
 |
|
|
subject: calling non-static from static context
|
|
|