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 are 3 data types?

735


What is variable and example?

707


How do you get the length of a string in java?

727


Is java util regex pattern thread safe?

719


Hi all, I am dng a mini project on FileSplitter application which splits the GBs of logfile into Smaller chunks(mbs) depending on the split size." How to handle GBs file? I am getting OutOfMemoryException, when I input such GB sized file. Thx

1817


What is this keyword used for?

863


What is a function easy definition?

721


What is a blocking method in Java?

804


What are computer functions?

686


Why multiple inheritance is not supported by java?

702


Can we split string with in java?

731


What isan abstract class and when do you use it?

1162


What is string immutability?

728


What is a ternary operator in java?

737


What is mvc in java?

763