Abstract Classes Page 197-205
Page 198 Animal Inheritance Tree Good basis for the structure Page 199 – New wolf; New Hippo from Animal class. Can we create a new animal object from the animal class????
Page 200 What does a new Animal () object look like?? What would the instance variables be? Some classes just should NOT be instantiated Certain classes are created ONLY to be SuperClasses; ONLY to be inherited from There is a simple way to prevent a class from being instantiated
Abstract Marking the class as “abstract” Abstract class Canine extends Animal When designing your inheritance structure, you must decide which classes are abstract and which are concrete. Concrete classes are those that are specific enough to be instantiated. A concrete class means it’s OK to make objects of that type
Abstract – cont’d An abstract class has virtually no use, no value, no purpose in life, unless it is extended With an abstract class, the guys doing the work at runtime are instances of a subclass of your abstract class. Look at Java API for examples - JComponent
Page 202 Look at illustration – top of page 202. Abstract Methods You can mark methods abstract, too An abstract class means the class must be extended An abstract method means the method must be overridden. An abstract method has no body. End with ;
Abstract Methods – cont’d If you declare an abstract method, you MUST mark the class abstract as well. You can’t have an abstract method in a non-abstract class. You MUST implement all abstract methods Implementing an abstract method is just like overriding a method Abstract methods – no body – exist only for polymorphism First concrete class in the inheritance tree must implement all abstract methods.