• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem in running abstract class

 
babul bansal
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


F:\scjp>javac child.java
child.java:6: child is not abstract and does not override abstract method

display() in child
public class child extends parent{
^
child.java:7: abstract methods cannot have a body
public abstract void display(){
^
2 errors

What is this error?
 
Denise Advincula
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


public class child extends parent{
public abstract void display(){
System.out.println("parent");
}
..



You should remove the abstract modifier from the child class' display() method...

To further elaborate, the error occured because the compiler may have interpreted the code as either creating a plain abstract method or implementing an abstract method.

If the child's method display() is marked abstract it should have no body and the child class should be marked abstract too. If that is the case the next concrete subclass of child (class that's not marked abstract) have to implement all the abstract methods up the inheritance tree.

Should you choose just to provide the abstract method implementation of the class parent's display() method, then just removing the abstract modifier will be enough.

Hope this helps.
[ August 15, 2008: Message edited by: Denise Saulon ]
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do not mark the child class method abstract, since you are implementing it.
 
babul bansal
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well this is a blunder mistake

Thanks for correcting me.
 
babul bansal
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well this is a blunder mistake

Thanks for correcting me.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic