previous |
start |
next
Inheritance
- Inheritance: extend classes by adding or redefining methods,
and adding instance fields
- Example: Savings account = bank account with interest
- class SavingsAccount extends BankAccount
{
new methods
new instance fields
}
- All methods of BankAccount are automatically
inherited
- Ok to call deposit, getBalance on
SavingsAccount object
- Extended class = superclass, extending class =
subclass
- Inheritance is different from realizing an interface
-
- Interface is not a class
- Interface supplies no instance fields or methods to
inherit
previous |
start |
next