how to make the double-tone class ? as we have singletone
class..?



how to make the double-tone class ? as we have singletone class..?..

Answer / sagar kumar

public class DoubletonTest {
public static void main(String[] args) {
Helloo h1=Helloo.getHello(1);
Helloo h2=Helloo.getHello(2);
Helloo h3=Helloo.FIRST;
Helloo h4=Helloo.SECOND;
System.out.println(h1);
System.out.println(h2);
System.out.println(h3);
System.out.println(h4);
System.out.println(h1==h3);//true
System.out.println(h2==h4);//true

}
}
class Helloo{
private Helloo(){

}
final static public Helloo FIRST=new Helloo();
final static public Helloo SECOND=new Helloo();

static public Helloo getHello(int val){
if (val<1 || val>2) {
throw new IllegalArgumentException(" "+val);
}
if (val==1) {
return FIRST;
}
return SECOND;
}
}

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More Core Java Interview Questions

When should I use stringbuffer?

0 Answers  


Suppose there is an array list [10,5,20,19,15,24].Print them in ascending & descending order in collection framework concept ???

2 Answers   Cognizant,


How is Garbage collection done in Java?

3 Answers   T3 Softwares,


What does string [] args mean?

0 Answers  


How to instantiate member inner class?

0 Answers  






What is methods and methodology?

0 Answers  


How many types of flags are there?

0 Answers  


Explain about version control?

0 Answers  


Difference String and String Buffer

4 Answers  


What are the major advantages of internal iteration over external iteration?

0 Answers  


how to handle exceptions in core applications?

2 Answers   CSS,


Can one thread block the other thread?

0 Answers  


Categories