This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes problem in running abstract class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "problem in running abstract class" Watch "problem in running abstract class" New topic
Author

problem in running abstract class

babul bansal
Greenhorn

Joined: Aug 11, 2007
Posts: 24


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

Joined: Jan 01, 2007
Posts: 160


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 ]

SCJP/OCPJP 6 | SCWCD/OCPJWCD 5 | OCMJEA in progress...
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6657
    
    5

Do not mark the child class method abstract, since you are implementing it.


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
babul bansal
Greenhorn

Joined: Aug 11, 2007
Posts: 24
Well this is a blunder mistake

Thanks for correcting me.
babul bansal
Greenhorn

Joined: Aug 11, 2007
Posts: 24
Well this is a blunder mistake

Thanks for correcting me.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem in running abstract class
 
Similar Threads
query on method over riding
why is an interface's varable static, and a method not allowed to be static?
problem on extending a class declared on the same package!!
init blocks example
Problem -- Virtual Method Invocation