answersLogoWhite

0

Hi, the answer for this question is as follows....:

class Demo

{

public static void main(String[] ar) throws Exception

{

Test1 d = new Test1();

Test1 d1 = new Test1();

boolean b = d1.equals(d);

Test1 d2 = new Test1();

System.out.println("" + b);

}

}

class Test1

{

static int count=0;

public Test1() throws Exception

{

try

{

if(count > 1)

{

throw new Exception();

}

else

System.out.println("Hi");

count=count + 1;

}

catch(Exception e){System.out.println("Can't have more than two instances");}

}

}

regards,

Amit

User Avatar

Wiki User

15y ago

Still curious? Ask our experts.

Chat with our AI personalities

BeauBeau
You're doing better than you think!
Chat with Beau
LaoLao
The path is yours to walk; I am only here to hold up a mirror.
Chat with Lao
JudyJudy
Simplicity is my specialty.
Chat with Judy

Add your answer:

Earn +20 pts
Q: How do you limit object creation in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp