3.2 Instance Variables, set Methods and get Methods

In this section, you’ll create two classes—Account (Fig. 3.1) and AccountTest (Fig. 3.2). Class AccountTest is an application class in which the main method will create and use an Account object to demonstrate class Account’s capabilities.

 1   // Fig. 3.1: Account.java 2   // Account class that contains a name instance variable 3   // and methods to set and get its value. 4  5   public class Account 6   { 7      private String name; // instance variable  8  9      // method to set the name in the object       10      public void setName(String name)              11      {                                             12         this.name = name; // store the name ...

Get Java™ How To Program (Early Objects), Tenth 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.