class is abstract cannot be instantiated code example

Example: class is abstract cannot be instantiated

An abstract class is a class that is declared abstract —it may or may not 
include abstract methods. Abstract classes cannot be instantiated, 
but they can be subclassed. When an abstract class is subclassed, 
the subclass usually provides implementations for all of the abstract methods
in its parent class.

abstract class GraphicObject {
    int x, y;
    ...
    void moveTo(int newX, int newY) {
        ...
    }
    abstract void draw();
    abstract void resize();
}

// extending abstract class
class Circle extends GraphicObject {
    void draw() {
        ...
    }
    void resize() {
        ...
    }
}
class Rectangle extends GraphicObject {
    void draw() {
        ...
    }
    void resize() {
        ...
    }
}

Tags:

Misc Example