Creating and manipulating an Account object in java:Once main begins executing, it may call other methods in this and other classes;those may, in turn, call other methods, and so on. Class AccountTest’s main method creates one Account object and calls its getName and setName methods. Such a class is sometimes called a driver class—just as a Person object drives a Car object by telling it what to do (go faster, go slower, turn left, turn right, etc.), class AccountTest drives an Account object, telling it what to do by calling its methods.
Creating and manipulating an Account object in java
/ Fig. 3.2: AccountTest.java
// Creating and manipulating an Account object.
import java.util.Scanner;
public class AccountTest
{
public static void main(String[] args)
{
// create a Scanner object to obtain input from the command window
Scanner input = new Scanner(System.in);
// display initial value of name (null)
System.out.printf("Initial name is: %s%n%n", );
// prompt for and read name
System.out.println("Please enter the name:");
System.out.println(); // outputs a blank line
// display the name stored in object myAccount
System.out.printf("Name in object myAccount is:%n%s%n",
);
}
} // end class AccountTest
Output
Initial name is: null
Please enter the name:
Bilal khan Meo
Name in object myAccount is:
Bilal khan Meo