Java Programming/Keywords/abstract

From Wikibooks, open books for an open world
< Java Programming | Keywords
Jump to: navigation, search

abstract is a Java keyword. ... It declares a class abstract, not all its methods are defined/implemented. Objects are not normally created from an abstract class. Rather, they are created from either a non-abstract subclass, or by having the functions declared alongside a new statement (which is not recommended).

It also declares a method abstract, that is, not implemented in the abstract class. A method cannot be declared abstract in a non abstract class.

Syntact:

public abstract class ClassName
or
abstract public class ClassName

and for methods in an abstract class :

public abstract void methodName();  // --- No body, no implementation ---
or
abstract public void methodName();  // --- No body, no implementation ---


For example:

Computer code
public abstract ClassName
 {
    // --- This method does not have a body; it is abstract. ---
    public abstract void abstractMethod();
 
    // --- This method does have a body; it is implemented in the abstract class and gives a default behavior. ---
    public void normalMethod()
    {
        ...
    }
 }
Personal tools
Namespaces
Variants
Actions
Navigation
Community
Toolbox
Sister projects
Print/export