previous |
start |
next
Converting Between Types
- Can convert from class type to realized interface type:
BankAccount account = new BankAccount(10000);
Measurable x = account; // OK
- Same interface type variable can hold reference to
Coin
x = new Coin(0.1, "dime"); // OK
- Cannot convert between unrelated types
x = new Rectangle(5, 10, 20, 30); // ERROR
previous |
start |
next