• Post Reply Bookmark Topic Watch Topic
  • New Topic

Error message (dazed and confused)  RSS feed

 
David Maltese
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
This is my first time posting on any programming site, so please excuse me if I make mistakes. I usually try to figure things out for myself, but I really do need help with this one.

I am getting this error message:
Inventory3A1.java:119: illegal start of type
super (int item, String name, int quantity, double price);


Below is the code containing the line in question:


If anyone can show me what to do, I would greatly appreciate it. The more obvious the better, as my mind has turned to clay.
Thank you!!!
 
Claude Moore
Ranch Hand
Posts: 924
9
IBM DB2 Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi David,

first of all.. try to recall or review what "super" actually means... then I'm quite sure you'll find the answer on your way......

Claude.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That, plus recall where you can, and cannot, put arbitrary Java statements.

And welcome to JavaRanch!
 
David Maltese
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

Thank you for your input! I really do appreciate it

I'm sure it's a relatively easy fix, but I'm in that mental state where I've blinded myself with overthinking, and frustrated over the compiler errors I keep getting. I guess I'd like someone to look over the code and show me what I've done wrong. Like I said, I usually try to figure everything out for myself, but the last few days of working on this have left me achy and dazed!
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't call super in random places.
 
Claude Moore
Ranch Hand
Posts: 924
9
IBM DB2 Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Maltese wrote:

Below is the code containing the line in question:




You're invoking a method (in this case, a constructor) outside a method.
 
Sunil Kumar
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are couple of problems in your code.
1. you are "calling" the constructor and providing data types for the variables, that looks like you wanted to define the constructor, which you cannot do. Dont use data types.
2. At line 11.

i guess you places ";" accidently. This is like creating constructor without body. Then line 12 will be considered as a statement where "year" is yet not defined

3. super can only be called in first line of the constructor because
super() is called implicitly in any constructor of a class at the first line. For example in a class Test.java

is equivalent to


Hence to override, you need to call your super constructor in the first line of the constructor.
 
David Maltese
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,

Thank you all for the help! I got it sorted out using your advice. I knew it was a relatively easy fix, but my mind had simply stopped functioning.

Thank you again!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!