90 likes | 212 Views
Chapter 8. Serious Polymorphism. Overview. When to not instantiate Abstract Classes Abstract Methods Class Object Casting and Object reference Multiple Inheritance Problem Interfaces. When to not instantiate. Sometimes a superclass is so generic as to be pointless to instantiate
E N D
Chapter 8 Serious Polymorphism
Overview • When to not instantiate • Abstract Classes • Abstract Methods • Class Object • Casting and Object reference • Multiple Inheritance Problem • Interfaces
When to not instantiate • Sometimes a superclass is so generic as to be pointless to instantiate • This is not bad because the framework for the sub classes is still created • For example, creating a new object of type animal is pointless if in ALL other subclasses all properties are overridden
Abstract Classes • A class can be protected from instantiation by the abstract command • This prevents a new object instance to be created. • You can still make a reference variable however
Abstract Methods • Abstract classes can still have inheritable methods • To make sure that subclasses must write their own methods, individual methods can be made abstract • This can only be done in abstract classes
Class Object • There is the mother of all superclasses, class Object • Every class by default inherits directly or indirectly from class Object • Some Object methods: • equals() • getClass() • hashCode() • toString()