One way of doing this would be:
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();
}
}
Click Here to See Answer .....
Did you like this article ?
Subscribe to my RSS feed and get more JAVA Question, and Guideline, Plus a lot more great advice to help your Software Career.
Subscribe to my RSS feed and get more JAVA Question, and Guideline, Plus a lot more great advice to help your Software Career.
0 comments:
Post a Comment