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

Program to Find the second largest element in an array.

580


Why java strings are immutable in nature?

583


Can we convert stringbuffer to string?

561


How many bytes is a string in java?

527


Explain the importance of thread scheduler in java?

591






What is method reference?

511


What is sizeof in java?

552


What is the use of conditional statement?

556


What do you mean by boolean?

564


How do you end a program?

540


What are java threads?

612


What is an example of declaration?

515


Can a static class have a constructor java?

541


Tell some latest versions in JAVA related areas?

550


What is the right data type to represent a price in java?

562