Presentation is loading. Please wait.

Presentation is loading. Please wait.

Polymorphism CSE 115 Spring 2006 March 6, 8 & 10, 2006.

Similar presentations


Presentation on theme: "Polymorphism CSE 115 Spring 2006 March 6, 8 & 10, 2006."— Presentation transcript:

1 Polymorphism CSE 115 Spring 2006 March 6, 8 & 10, 2006

2 A Variable Declaration… Bird bird = new Duck();  Can we do this? Only if Duck is a subclass of Bird or if Duck is a class that implements the Bird interface.

3 A Variable Declaration… Bird bird = new Duck();  Bird is the declared type of the variable bird  Duck is the actual type of the variable bird

4 Subtype Polymorphism  Objects of the subclass can be provided to stand in for objects of the superclass.

5 Polymorphism  When there is a difference between the declared type and actual type of an object, the only methods that can be called are those that are declared in the declared type. The methods that get executed are those in the actual type.

6 Examples  Flyer-Bird-Duck-Penguin example  Began start/stop bouncing ball example


Download ppt "Polymorphism CSE 115 Spring 2006 March 6, 8 & 10, 2006."

Similar presentations


Ads by Google