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

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

What is integer parseint?

553


What is the difference between dom and sax parser in java?

538


What is tcp ip in java?

592


What is the string function?

561


What is the difference between class forname and new?

552






What is the += operator called?

581


What is the file type?

561


What is a method header?

550


What is the final keyword?

559


How do you differentiate abstract class from interface?

532


Explain the difference between the public, private, final, protected, and default modifiers?

555


Is array synchronized in java?

557


Why Set interface contains unique elements, what internally implemented for this so that it contains unique elements?

7427


What happens if a constructor is declared private?

539


Is linked list a linear or non-linear data structure?

551