package switchblocks;
public class SwitchBlocks
{
public static void main(String args[])
{
int input = 100;
do
{
System.out.print("\n\tEnter a positive integer (0 to stop)");
input = MyInput.readInt();
switch (input)
{
case 1: A myA = new A(); break;
case 2: B myB = new B(); break;
default: System.out.print("\n\tNo new objects created");
}
} while (input > 0);
System.out.print("\n\n\tNumber of A objects created = " + A.getA());
System.out.print("\n\n\tNumber of B objects created = " + B.getB());
}
}
class A
{
private static int nobjects = 0;
public A() { nobjects++; }
public static int getA() { return nobjects; }
}
class B
{
private static int nobjects = 0;
public B() { nobjects++; }
public static int getB() { return nobjects; }
}

While pursuing a Computer Science degree, I founded DaniWeb.com, an online community for developers and IT professionals. I coded the backend platform from the ground up and I also do all of the advertising sales and SEO. I'm a super-geeky programmer with a passion for Internet marketing.

The article starter has earned a lot of community kudos, and such articles offer a bounty for quality replies.