lecture8 - CS 116 OBJECT ORIENTED PROGRAMMING II LECTURE 8...

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

View Full Document Right Arrow Icon
CS 116 OBJECT ORIENTED PROGRAMMING II LECTURE 8 GEORGE KOUTSOGIANNAKIS Copyright: SPRING 2010 Illinois Institute of Technology/George Koutsogiannakis 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
Last week’s topics Inheritance Concepts Inheritance Design Inherited Members of a Class Subclass Constructors Overriding Inherited Methods 2
Background image of page 2
This week ‘s Topics Adding Specialization to the Subclass Abstract Classes and Methods 3
Background image of page 3

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

View Full DocumentRight Arrow Icon
The BankAccount Heirarchy 4 Note 1: + indicates public and – indicates private Note 2: return types Are shown after the Name and arguments listing of a method
Background image of page 4
Adding Specialization A subclass can define new fields and methods. Our CheckingAccount class adds these instance variables: monthlyFee, a double DEFAULT_FEE , a double constant these methods: setMonthlyFee, the accessor getMonthlyFee , the mutator applyMonthlyFee , which charges the monthly fee to the account 5
Background image of page 5

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

View Full DocumentRight Arrow Icon
The applyMonthlyFee Method Because balance is private in the BankAccount class, the applyMonthlyFee method calls the withdraw method to subtract the monthly fee from the balance: public void applyMonthlyFee( ) { withdraw( monthlyFee ); } Why the indirect call and not a direct call to balance? See Examples 10.7 and 10.8 in text 6
Background image of page 6
The superclasses in a class hierarchy should define fields and methods common to all subclasses. The subclasses should add specialized fields and methods. That is called specialization SOFTWARE ENGINEERING TIP 7
Background image of page 7

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

View Full DocumentRight Arrow Icon
Overriding Inherited Methods A subclass can override (or replace) an inherited method by providing a new version of the method. The API of the new version must match the inherited method. When the client calls the method, it will call
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 24

lecture8 - CS 116 OBJECT ORIENTED PROGRAMMING II LECTURE 8...

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

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