1. Abstract Class
Definition
- An abstract class is a class that is declared abstract—it may or may not include abstract methods.
- An abstract classes cannot be instantiated.
- An abstract classes can be subclassed.
- If a class include abstract methods, the class itself must be declared abstract.
Some Code example:
public abstract class GraphicObject {
// declare fields
// declare nonabstract methods
abstract void draw();
}
2. Abstract Methods
The subclass of the abstract class must implement all the abstract methods in its parent class. IF NOT, then the subclass must be declared abstract too
3. Interface
- Interface cannot be instantiated either.
- Interface may also contain a mix of methods declared with or without implementation .
- All fields are automatically
public, static
, andfinal
. - All methods that you declare or define (as default methods) are public.
- Methods in an
interface
(see the Interfaces section) that are not declared as default or static are implicitly abstract, so the abstract modifier is not used with interface methods. (It can be used, but it is unnecessary.)