• 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

Error message (dazed and confused)

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!!
 
Bartender
Posts: 1363
39
IBM DB2 Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't call super in random places.
 
Claude Moore
Bartender
Posts: 1363
39
IBM DB2 Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
reply
    Bookmark Topic Watch Topic
  • New Topic