• 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

cannot find symbol

 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm confused by this error. I have three files, Employee.java, SalariedEmployee.java, and SalariedTest.java, respectively:



here is the error:

 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you have a subclass constructor, and you don't explicitly call a superclass constructor from it, then an implicit call to the no-args constructor of the superclass is inserted. Like in any other class, if there is no constructor in the superclass, then a default no-args constructor will be created. However, if there is already a constructor in the class definition, then a default constructor will not be created.

It's telling you here that it inserted an implicit call to the no-args constructor of the superclass, but there isn't one.
 
Jesse Crockett
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, I put a no arg constructor initializing name to "john doe" and dept to 0, and the code works fine. But how do I get rid of that, because my professor probably will not like it. Thanks :-)

Also, is my overridded hashCode() okay?
[ September 22, 2006: Message edited by: Jesse Crockett ]
 
Keith Lynn
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well as your code stands, it won't matter if your professor doesn't like it, you have to have the no-args constructor. I would say that your professor would probably want you to reexamine your two class definitions and make use of inheritance. Remember that you can explicitly invoke a constructor from the superclass from the subclass constructor, and non-private variables in the superclass are inherited by the subclass in this case.
 
Jesse Crockett
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have rewritten the code so the constructor call:



and the variables are protected instead of private

will you look closely at my equals() method in SalariedEmployee class and let me know if i am doing it right? it seems to work, but i'm not sure if it's the right way. thanks again :-)
 
Keith Lynn
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Remember that the signature of the equals method that is inherited from Object is equals(Object).
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic