| Author |
cannot find symbol
|
Jesse Crockett
Ranch Hand
Joined: Feb 03, 2005
Posts: 129
|
|
I'm confused by this error. I have three files, Employee.java, SalariedEmployee.java, and SalariedTest.java, respectively: here is the error:
|
 |
Keith Lynn
Ranch Hand
Joined: Feb 07, 2005
Posts: 2341
|
|
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
Joined: Feb 03, 2005
Posts: 129
|
|
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
Joined: Feb 07, 2005
Posts: 2341
|
|
|
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
Joined: Feb 03, 2005
Posts: 129
|
|
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
Joined: Feb 07, 2005
Posts: 2341
|
|
|
Remember that the signature of the equals method that is inherited from Object is equals(Object).
|
 |
 |
|
|
subject: cannot find symbol
|
|
|