Hey
I have a problem of how can i modify the bankAccount in order to count how many instances of the class have been created.

I think of that but the problem is that don't know how to add it to the original program :

private static int instanceCount = 0;
public CountTest()
{
instanceCount++;
}
pubic static int getinstanceCount()
{
return instanceCount;
}


Bank Account

public class BankAccount
{
	private int balance;

	public BankAccount(int initialBalance)
	{
		this.deposit( initialBalance );
	}
	
	public void withdraw( int amount)
	{
		balance = balance - amount;
	}
	
	public void deposit (int amount)
	{
		balance = balance + amount;
	}
	
	public int getBalance()
	{
		return balance;
	}
}


Thanks in advnace and i hope that someone can help me !

if you just want to keep track of how many instances you create, add the static counter to the BankAccount class and increase it in the constructor.

But be aware that that will not keep track of the number of instances actually being accessible to the program, only the number of instances being created.
It also will not keep track of all instances being created anywhere at any time. It's limited to the scope of a single classloader.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.