//constructors CheckingAccount( String accNumber, String holder, int start ) { accountNumber = accNumber ; accountHolder = holder ; balance = start ; }
We have enough code to put together a test program. The test program will not do much, but it will compile and run.
class CheckingAccount { // instance variables String accountNumber; String accountHolder; int balance; //constructors CheckingAccount( String accNumber, String holder, int start ) { accountNumber = accNumber ; accountHolder = holder ; balance = start ; } // methods } class CheckingAccountTester { public static void main( String[] args ) { CheckingAccount account1 = new CheckingAccount( "123", "Bob", 100 ); System.out.println( account1.accountNumber + " " + account1.accountHolder + " " + account1.balance ); } }
This program can be copied to a file, compiled, and run in the usual way. The output will be:
C:\chap32>javac CheckingAccountTester.java C:\chap32>java CheckingAccountTester 123 Bob 100
If you prefer, you could put each class in its own source file
and then compile as above.
The results will be the same.
With an IDE, you can test the CheckingAccount
class
without a tester program.
What does the expression
account1.accountNumber
mean?
(Look in the println
statement to see where this
expression was used.)