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
What is meant by data hiding/encapsulation?
What are nested classes in java?
Which methods cannot be overridden in java?
What is hashmap in java?
What is the final field modifier?
Is java a prime method?
What is exception in java?
What is the function of log?
Which container method is used to cause a container to be laid out and redisplayed in java programming?
What is the purpose of final keyword and when to use it?
What does s mean in regex?
What is the difference between throw and throws in java?
Explain about method local inner classes or local inner classes in java?
Can we have static methods in an interface?
List any five features of java?