Can the abstract
modifier appear before a class, a method or a variable?
views:
422answers:
5It can appear before classes (to prevent from being instantiated and allow them to have abstract methods) and before methods (to signify that the method is not implemented in this class, but any non-abstract subclass must implement it).
The abstract modifier is placed before classes or methods. For a class, it means that it cannot be directly instantiated, but has to be subclassed. For a method, it means that it does not have an implementation in the class, but has to be implemented in a subclass. It cannot be applied to variables.
A class and a method. The abstract modifier is used to signify that a class/method is expected to be overridden. As a guide:
class - Contains unimplemented methods and cannot be instantiated.
method - No body, only signature. The enclosing class is abstract
Hope that helps.
Abstract can be put in a class declaration, as in
public abstract class Test{
//class implementation
}
...and in a method declaration, as in
public abstract void test();
On the argument: http://java.sun.com/docs/books/tutorial/java/IandI/abstract.html