THINK FIRST·CODE LATER

← All labs

BankAccount: encapsulation and a class counter

Problem

Write a BankAccount class with a private balance, a static counter of accounts created, an automatically assigned account number, deposit, withdraw that refuses to overdraw, and toString. Write a driver that creates three accounts and prints the number of accounts in existence.

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.