April 2019
Intermediate to advanced
360 pages
9h 17m
English
The CreateBankAccount class includes a private constructor, which will prevent attempts to instantiate more than one instance of the CreateBankAccount object. The getNewAccount() method checks whether the newAccount already exists and provides contextual feedback to the user:
public class CreateBankAccount { private static CreateBankAccount newAccount; // constructor private CreateBankAccount() { } public static CreateBankAccount getNewAccount() { if (newAccount == null) { newAccount = new CreateBankAccount(); System.out.println("New Account created."); } else { System.out.println("Account already opened."); } return newAccount; }}
The Driver class, AccountDriver, prints a header label and then attempts to create ...
Read now
Unlock full access