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

use of wrapper classes?

3 Answers   IBM,


What is “try and catch” in java

5 Answers   Cap Gemini, TCS,


What is an object?s lock? Give name of object?s that have locks?

2 Answers  


What are the default and parameterized constructors?

0 Answers  


Explain list interface?

0 Answers  






Can interface be private in java?

0 Answers  


What is arraylist e?

0 Answers  


Is integer a class?

0 Answers  


What do you understand by synchronization?

0 Answers  


What is the meaning of nullable?

0 Answers  


List out five keywords related to exception handling ?

0 Answers  


How many bytes is 255 characters?

0 Answers  


Categories