• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

calling non-static from static context

 
marsha bianco
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • 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?
 
Dieter Quickfend
Bartender
Posts: 543
4
Java Netbeans IDE Redhat
  • 0
  • Mark post as helpful
  • send pies
  • 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?
 
Rob Spoor
Sheriff
Pie
Posts: 20396
47
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not GUI related; moving to Beginning Java.
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic