previous | start | next

Syntax 11.1: Inheritance

  class SubclassName extends SuperclassName
{
   methods
   instance fields

}

Example:

 
public class SavingsAccount extends BankAccount
{
public SavingsAccount(double rate)
{
interestRate = rate;
}

public void addInterest()
{
double interest = getBalance() * interestRate / 100;
deposit(interest);
}

private double interestRate;
}

Purpose:

To define a new class that inherits from an existing class, and define the methods and instance fields that are added in the new class.



previous | start | next