Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Super class

 
jon ladd
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
jon ladd
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nope. You need to write an Employee constructor:
 
jon ladd
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks that helped out alot. But now I am looking at errors in my getPrate and payrate.
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But now I am looking at errors in my getPrate and payrate.
Welcome to the glamorous world of programming.
 
jon ladd
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java is case-sensitive: use String, not string.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
jon ladd
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the help.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic