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

What is the difference between multitasking and multithreading in Java

0 Answers   Sans Pareil IT Services,


Can we overload the methods by making them static?

0 Answers  


Which One is optimal to choose ? Syncronized hash map or Hash table with single thread model? How can a hash map syncronized with out using syncrozed blocks in programm?

3 Answers   Four soft,


what is the difference b/w PUT and POST method to send data to the server

5 Answers   Mind Tree,


Can a top level class be private or protected?

0 Answers  






Is main is a keyword?

0 Answers  


What is the difference between == and === javascript?

0 Answers  


What is string in java?

0 Answers  


What is methodological framework?

0 Answers  


What is hashset in java?

0 Answers  


What is an example of a conditional statement?

0 Answers  


What is a function argument in java?

0 Answers  


Categories