Presentation is loading. Please wait.

Presentation is loading. Please wait.

C HAPTER 8 Serious Polymorphism. O VERVIEW When to not instantiate Abstract Classes Abstract Methods Class Object Casting and Object reference Multiple.

Similar presentations


Presentation on theme: "C HAPTER 8 Serious Polymorphism. O VERVIEW When to not instantiate Abstract Classes Abstract Methods Class Object Casting and Object reference Multiple."— Presentation transcript:

1 C HAPTER 8 Serious Polymorphism

2 O VERVIEW When to not instantiate Abstract Classes Abstract Methods Class Object Casting and Object reference Multiple Inheritance Problem Interfaces

3 W HEN 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

4 A BSTRACT C LASSES 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

5 A BSTRACT M ETHODS 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

6 C LASS O BJECT 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()

7 C ASTING AND O BJECT REFERENCE

8 M ULTIPLE I NHERITANCE P ROBLEM

9 I NTERFACES


Download ppt "C HAPTER 8 Serious Polymorphism. O VERVIEW When to not instantiate Abstract Classes Abstract Methods Class Object Casting and Object reference Multiple."

Similar presentations


Ads by Google