Abstract classes

The abstract keyword allows to mark class as abstract and to specify abstract methods.

The purpose of an abstract class is to provide implementation of a common method to all subclasses or to provide a default implementation. For example, the Shape class may be an abstract class for the Circle and Rectangle classes.

Although an abstract class may have constructors, you cannot create an instance.

An abstract method is a method without implementation. An abstract class may not have any abstract methods.

You can create an anonymous class from an abstract class.

public abstract class Shape{
    public abstract void draw(Canvas c);
    // ... other fields and methods

public class Rectangle extends Shape {
    public void draw(Canvas c){
        // ...
Shape shape = new Shape() { // anonymous @Override public void draw(Canvas c) { // ... } };