aspose file tools*
The moose likes Beginning Java and the fly likes Super class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Super class" Watch "Super class" New topic
Author

Super class

jon ladd
Ranch Hand

Joined: Feb 11, 2003
Posts: 53
I have an error with my super class it is, Illegal start of type at line 133.
Any help would be great thanks
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937
The line super(iFirstName, iLastName) in your code is out of place. If your intent is to call a constructor of the super class, it must be the first line in the constructor of the derived class.
Eugene.
jon ladd
Ranch Hand

Joined: Feb 11, 2003
Posts: 53
I put this super(iFirstName, iLastName)right at the begging of the employee class and still gave me the same error.
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
I put this super(iFirstName, iLastName)right at the begging of the employee class and still gave me the same error.
As Eugene stated, you have to put it as the first line of the Employee consturctor, not just at the top of the class. A super constructor can only be called from inside a subs constructor and it must be the first line of the constructor.


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
jon ladd
Ranch Hand

Joined: Feb 11, 2003
Posts: 53
class Employee extends Person {
super(iFirstName, iLastName);
private double payrate;
public void setPrate(double newPrate){ payrate = newPrate;}
public double getPrate() {
return payrate;
Is this the right location?
Augustin Caine
Greenhorn

Joined: Apr 24, 2003
Posts: 8
Nope. You don't call super there. Put it in the constructor of the subclass Try it this way:
class Employee extends Person {
private double payrate;
public Employee(){
super(iFirstName, iLastName);
// statements in constructor
}
public void setPrate(double newPrate){ payrate = newPrate;}
public double getPrate() {
return payrate;
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Nope. You need to write an Employee constructor:
jon ladd
Ranch Hand

Joined: Feb 11, 2003
Posts: 53
Thanks that helped out alot. But now I am looking at errors in my getPrate and payrate.
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
But now I am looking at errors in my getPrate and payrate.
Welcome to the glamorous world of programming.
jon ladd
Ranch Hand

Joined: Feb 11, 2003
Posts: 53
thanks alot for the help I see were I messed up.
The only other thing that confusing me is the error about my strings Class string not found in class Person at line, it does it at every place i have a string.
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1821

Java is case-sensitive: use String, not string.
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
If you have any more errors, please post your revised code along with the error message. Also, please clearly note which line causes the error. I don't know how to count past 10! Even if I did, I wouldn't want to.


Java API Documentation
The Java Tutorial
jon ladd
Ranch Hand

Joined: Feb 11, 2003
Posts: 53
thanks for the help.
 
 
subject: Super class