PolymorphismA Variable Declaration…Slide 3Subtype PolymorphismSlide 5ExamplesPolymorphismCSE 115 Spring 2006March 6, 8 & 10, 2006A 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.A Variable Declaration…Bird bird = new Duck();Bird is the declared type of the variable birdDuck is the actual type of the variable birdSubtype PolymorphismObjects of the subclass can be provided to stand in for objects of the superclass.PolymorphismWhen 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.ExamplesFlyer-Bird-Duck-Penguin exampleBegan start/stop bouncing ball
View Full Document