Thursday, March 12, 2009

It is valid to declare an inherited method as abstract (CoreJava)

Question :It is valid to declare an inherited method as abstract? (CoreJava)
Answer :Yes its valid to declare an inherited method abstract. But it would be of
no use as you need to define the class
abstract again.
e.g.
abstract class AbsTest
{
abstract void setName(String name);
}
public class AbsTest1 extends AbsTest //compile error is thrown as there is
an abstract method, declare the class abstract
{
abstract void setName(String name){} // error, abstract method
cannot have body
}

No comments: