Inheritance, "Is a" relationship
superclass (or base or parent class)
subclass (or derived or child class)
super()
Object class
extends
override
Polymorphism
dynamic binding
Abstract (vs concrete) class
Interfaces
protected access
package access
inheritance hierarchy
overriding methods (e.g. equals)
instanceof operator
comparable interface
super()
in the first line of constructor
super.method_name()
anywhere in a subclass method.
Shape[] shapes = new Shape[3];
shapes[0] = new Circle(2);
shapes[1] = new Rectangle(2,3);
shapes[2] = new Square(5);
for (int i=0; i < shapes.length; i++) {
System.out.println("The area for " + shapes[i] + " is " + shapes[i].calcArea());
}
public abstract class Shape {
public abstract double calcArea();
...
Must define method in the subclass. Can't create a Shape object; can only create a subclass.
final
so that one can't override a method in the subclass.
Object
instanceof
operator can be used to check what type of object you have. For example, if you need to
cast an object. Should be used sparingly. Don't use as a way to implement different behavior, i.e. to bypass polymorphism.
implements
keyword.