anukampa,
What is the difference between abstract methos and a method without any body i.e. only empty braces are given for methos but no body is there.
One important difference is that an abstract method may only appear in an abstract class. You are right to notice a similarity between an abstract method and a regular method that has no body. They are similar in so far as neither seems to really "do anything," but each serves a distinct purpose.
An abstract method doesn't have a body because implementation of the method is defered to a subclass of the abstract class that contains the method. Declaring an abstract method foo() is like making a promise that some future sublcass will know how to do something that can be invoked by the name foo(). However, since the implementation of the method is defered, you cannot call the original, abstract method.
As to the other option you mention, non-abstract methods with no bodies, I would just point out that, even if a method has no body, it is still perfectly legal to call that method. As, to why you might
want to do this, maybe somebody else can fill that in.
Why cant we use empty method in the place of abstract method ?
I'm not sure whatyou mean by this? You can override an abstract method with a non-abstract method that has no body. have a look at the following code:
abstract class Super {
public abstract void foo(); // abstract method
} // class Super
class Sub extends Super {
public void foo() {} // non-abstract, no body code
} // class Sub
Is this what you were asking?
Or are you asking why we would make the method abstract in the first place?
[ April 26, 2002: Message edited by: Dave Winn ]