|
Computer Science (CSCI)
Department |
|||
|
|||
(Example code and figures from Computing Concepts with Java Essentials, 3rd
edition, by Cay Horstmann.
Visit www.wiley.com/college/horstmann
for information on the current edition of this excellent text.)
SavingsAccount collegeFund = new SavingsAccount(10); |
SavingsAccount collegeFund = new SavingsAccount(10); |
Invoking a Method
collegeFund.addInterest(); // OK anAccount.addInterest(); // not legal |
anAccount.deposit(); // SavingsAccount deposit method invoked |
public void transfer(double amount, BankAccount other) |
CheckingAccount harrysChecking = ...; SavingsAccount momsAccount = ...; momsAccount.transfer(1000, harrysChecking); |
other.deposit(amount); |

Rectangle box = new Rectangle(5, 10, 20, 30); System.out.println(box); prints out: java.awt.Rectangle[x=5,y=10,width=20,height=30] |
Rectangle box = new Rectangle(5, 10, 20, 30); String info = "box has " + box; System.out.println(info); prints out: box has java.awt.Rectangle[x=5,y=10,width=20,height=30] |
BankAccount vacationFund = ...; System.out.println(vacationFund); prints out something like: BankAccount@d2460bf |
public class BankAccount |
Coin coin1 = new ...;
Coin coin2 = coin1;
...
if (coin1 == coin2)
System.out.println("same location");
|

Coin coin1 = new ...;
Coin coin2 = new ...;
...
if (coin1.equals(coin2))
System.out.println("same content");
|

public class Coin |
|
Exercise - overriding inherited methods |