Assignment: Module 03- Part 03
![]() |
Assignment: Module 03- Part 03 |
Two Constructors of Account class accepts integer accountNumber 1 parameter) and integer account number and string customerName parameters. Call those constructors from AccountTest class and display the values.
Note: create display() to display values.
Input:
Account (101)
Account(101, “Vishal”);
Output:
101
101
Vishal
Here is the code for the Account and AccountTest classes in Java:
class Account {
private int accountNumber;
private String customerName;
public Account(int accountNumber) {
this.accountNumber = accountNumber;
}
public Account(int accountNumber, String customerName) {
this(accountNumber);
this.customerName = customerName;
}
public void display() {
System.out.println("Account Number: " + accountNumber);
System.out.println("Customer Name: " + customerName);
}
}
class AccountTest {
public static void main(String[] args) {
Account account1 = new Account(101);
System.out.println("First Account:");
account1.display();
Account account2 = new Account(101, "Vishal");
System.out.println("Second Account:");
account2.display();
}
}
And here is the output:
First Account:
Account Number: 101
Customer Name: null
Second Account:
Account Number: 101
Customer Name: Vishal