Inheritance in Java
A class may extend another class by adding methods and fields and
by replacing (overriding) methods and fields by new implementations.
The extended class is called a subclass. The original class is the
superclass.
- The methods and fields that are inherited are can be accessed as if
they were methods and fields of the superclass.
- The word super is used to refer explicitly to a method or field
of the superclass. (This can be necessary if methods or fields were overridden.)
- A class can extend only one other class. This is called
single inheritance.
Example:
class Pixel extends Point {
public Color color;
public Pixel(x, y, col) {
super(x, y);
color = col;
}
}