Account Class with an Instance Variable of Type double

Our next application (Figs. B.9B.10) contains a class named Account (Fig. B.9) that maintains the balance of a bank account. A typical bank services many accounts, each with its own balance, so line 7 declares an instance variable named balance of type double. It’s an instance variable because it’s declared in the body of the class but outside the class’s method declarations (lines 10–16, 19–22 and 25–28). Every instance (i.e., object) of class Account contains its own copy of balance.

 1   // Fig. B.9: Account.java 2   // Account class with a constructor to validate and 3   // initialize instance variable balance of type double. 4  5   public class Account ...

Get Android™ How to Program, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.