Loading

Exercise Number: 1

Static Variable

Scenario: Create a class BankAccount that keeps track of the total number of accounts created.

Task:

  • Implement a static variable totalAccounts that is incremented every time a new BankAccount is created.
  • Write a method getTotalAccounts to return the total number of accounts.
  • In the main method, create several BankAccount objects and display the total number of accounts created.
Expected Output:
Total accounts created: 3