05 Inheritance Updated
05 Inheritance Updated
Object-Oriented Programming:
Inheritance – Part 1
Java™ How to Program, 10/e
Late Objects Version
balance += amount;
}
public void withdraw(double amount) {
balance -= amount;
}
} © Copyright 1992-2015 by Pearson Education,
Inc. All Rights Reserved.
5.3 Example without inheritance
(Cont.)
public class SavingAccount {
private String type;
private String name;
private long number;
private double balance;
private double interestRate = 0.10;
public SavingAccount(String name, long number, double amount) {
type = “Saving account”;
this.name = name;
this.number = number;
balance = amount;
} We assume that all
required setters and
public void deposit(double amount) {
getters are defined
balance += amount;
}
public void withdraw(double amount) {
balance -= amount;
}
}
🞂 You must use the keyword super to call the superclass constructor.
Invoking a superclass constructor’s name in a subclass causes a syntax
error. Java requires that the statement that uses the keyword super
appear first in the constructor.