lecture9 - CS 116 OBJECT ORI ENTED PROGRAM M I NG I I...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS 116 OBJECT ORI ENTED PROGRAM M I NG I I LECTURE 9 GEORGE KOUTSOGI ANNAKI S Copyright: spring 2010 I llinois I nstitute of Technology/George Koutsogiannakis 1 Last week s Topics Adding Specialization to the Subclass Abstract Classes and Methods 2 New Topics Polymorphism New format for for loop . I nterfaces Multiple I nheritance 3 Polymorphism An important concept in inheritance is that an object of a subclass is also an object of any of its superclasses. That concept is the basis for an important OOP feature, called polymorphism . Polymorphism simplifies the processing of various objects in the same class hierarchy because we can use the same method call for any object in the hierarchy using a superclass object reference. 4 Polymorphism Requirements To use polymorphism, these conditions must be true: the classes are in the same hierarchy all subclasses override the same method a subclass object reference is assigned to a superclass object reference the superclass object reference is used to call the method 5 Example Suppose Figure is abstract and has an abstract method draw. Suppose that Circle and Square inherit from Figure and implement Figure s abstract method draw. 6 Example Suppose we have a class FigureClient. This class uses the previous classes to actually draw figures. i.e. (assuming that all classes are in the same folder) public FigureClient { Circle circle=new Circle(); Square square=new Square(); Figure figure; //just declaration, no instantiation is allowed figure=circle; figure.draw(); // a circle will be drawn figure=square; figure.draw(); // a square will be drawn now....
View Full Document

Page1 / 24

lecture9 - CS 116 OBJECT ORI ENTED PROGRAM M I NG I I...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online