CS 46A - Lecture 25

Cover page image

Pre-class reading

Inheritance Hierarchies

Inheritance Hierarchies

Inheritance Hierarchies

Inheritance Hierarchies

Inheritance Hierarchies

Lecture 25 Clicker Question 1

Should we place the addInterest method in the BankAccount class?

  1. No, not all bank accounts earn interest.
  2. No, it would be a syntax error to put it there because the SavingsAccount subclass has an addInterest method.
  3. It would be better to put it there so that checking accounts can earn interest
  4. It would be better to put it there so that we can later add time deposit accounts that earn interest

Inheritance Hierarchies

Inheritance Hierarchies

Inheritance Hierarchies

Inheritance Hierarchies

Inheritance Hierarchies

ch10/accounts/SavingsAccount.java

Your browser does not support the <object> tag.

Syntax 10.1 Inheritance

Inheritance

Lecture 25 Clicker Question 2

Which instance variables does an object of class SavingsAccount have?

  1. It has no instance variables
  2. interestRate
  3. interestRate and balance
  4. interestRate, balance, and interest

Lecture 25 Clicker Question 3

Which methods that you can apply to SavingsAccount objects?

  1. deposit and withdraw, but not addInterest
  2. deposit and withdraw, but not getBalance
  3. addInterest but not deposit, withdraw, or getBalance
  4. deposit, withdraw, getBalance, and addInterest

Common Error: Shadowing Instance Variables

Common Error: Shadowing Instance variables

Overriding Methods

Overriding Methods

Overriding Methods

Overriding Methods

Overriding Methods

Syntax 10.2 Calling a Superclass Method

Calling a Superclass Method