super()
in the first line of constructor
super.method_name()
anywhere in a subclass method.
Employee[] employees = new Employee[3];
employees[0] = new Employee();
employees[1] = new HourlyEmployee();
employees[2] = new SalariedEmployee();
for (int i=0; i < employees.length; i++) {
System.out.println("The employee is " + employees[i].getName() +
" and their pay is " + employees[i].calcPaycheck());
}
public abstract class Employee {
public abstract double calcPaycheck();
...
Must define method in the subclass. Can no longer create an Employee 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.
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 |