previous | start | next

Inheritance, Classes, and Interfaces

A class can inherit from exactly one other class. 

E.g., SavingsAccount inherits from (extends) BankAccount:

public class SavingsAccount extends BankAccount ...

This form of inheritance means that 

1. A SavingsAccount instance has each one of the data members defined
in BankAccount (all data members are "inherited")

2. A SavingsAccount instance inherits all the methods (and their
implementations) defined in BankAccount.

Java Facts:
a. A class can inherit from only one class
b. A class can inherit from multiple interfaces 
c. A class can do both a. and b.

E.g., 

public class Y extends X implements I, J
{


}

X and Y are classes
I and J are interfaces

   


previous | start | next