• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with abstract methods

 
jon ladd
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its giveing me these errors "Class Employee should be declared abstract; it does not define method fullname() in class Employee at line 128"
andClass Customer should be declared abstract; it does not define method fullname() in class Customer at line 161. There not suppose to be abstrac just the Person class is.
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to provide an implementation for public abstract void fullname() in order for the Employee class to be concrete (that is not abstract). So do something like this in Employee:

[ April 29, 2003: Message edited by: Michael Morris ]
 
jon ladd
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have this is on my employee class and my customer class.
public String toString() {
String result = fullname() + ", " + getPrate() ;
return result;
and it gives me this error 'void' type not allowed here at line 161
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The toString method does not provide a method body for fullname. Aparrantly the return type is also incorrectly declared in the Parent class. It should be public abstract String fullname(). In that case the method could be defined something like this in the Employee class:

[ April 29, 2003: Message edited by: Michael Morris ]
 
jon ladd
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
were are u saying thats suppose to go?
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think fullname() should even be abstract since every Person has full name, whether they are a Customer or an Employee. In other words, imho, the fullname() function that Michael gave should go in the Person class. If the Customer wants to do something different for its fullname() then Customer should have its own fullname() method that does the customizations necessary for a Customer.
HTH
Layne
 
jon ladd
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
were are u saying thats suppose to go?
 
Angela Poynton
Ranch Hand
Posts: 3143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you could really do with reading this it might help you out a bit.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic