ContactUs :

Please send your Questions & Answers or Feedback to "mohan@javabook.org"

I want to create two instances of a class, But when trying for creating third instance it should not allow me to create.What I have to do for making this?

public class test1
{
static int cntr=0;
test1()
{ cntr++;
if(cntr>2)
throw new NullPointerException();//u can define a new exception // for this
}
public static void main(String args[])
{
test1 t1= new test1();
System.out.println("hello 1");
test1 t2= new test1();
System.out.println("hello 2");
test1 t3= new test1();
}
}
Related Posts Plugin for WordPress, Blogger...
Flag Counter