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 newBankAccount
is created. - Write a method
getTotalAccounts
to return the total number of accounts. - In the
main
method, create severalBankAccount
objects and display the total number of accounts created.
Expected Output:
Total accounts created: 3