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

diff. b/w JAVA and javascript...

3 Answers   NIIT,


What are streams in java 8?

0 Answers  


Where are local variables stored?

0 Answers  


what is the difference b/w static and final methods?

1 Answers  


What is a qms manual?

0 Answers  






What is the difference between numeric and integer?

0 Answers  


What is java literals?

0 Answers  


State the significance of public, private, protected class?

0 Answers  


What are the different approaches to implement a function to generate a random number?

0 Answers   Axtria, ITC Indian Tobacco Company,


What is the difference between preparedstatement and statement in java?

0 Answers  


What is a priority queue java?

0 Answers  


What is the difference between method overriding and overloading?

0 Answers  


Categories