Specifying the Public Interface of a Class

Behavior of bank account (abstraction):
    - deposit money
    - withdraw money
    - get balance

 

Methods of BankAccount class:
    - deposit
    - withdraw
    - getBalance

 

We want to support method calls such as the following:

harrysChecking.deposit(2000);
harrysChecking.withdraw(500);
System.out.println(harrysChecking.getBalance());

Method Definition

- access specifier (such as public)
-
return type (such as String or void)
-
method name (such as deposit)
-
list of parameters (double amount for deposit)
- method body in
{ }

 

Examples:
public
void deposit(double amount) { . . . }
public void withdraw(double amount) { . . . }
public double getBalance() { . . . }

 

Constructor Definition

Class Definition