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 |
Is it possible to compare various strings with the help of == operator? What are the risks involved?
Can we return null in java?
What is the difference between a synchronized method and a synchronized block?
Why can we not override static method?
What is incompatible types in java?
List out benefits of object oriented programming language?
How to find the index of the largest number in an arraylist java?
What is the purpose of the return statement?
What is the difference between ArrayList and Vector? which one is better in Java
0 Answers SkillGun Technologies,
Is integer immutable in java?
how can u apply shallow cloning and deep cloning to create object?
explain about jre and jvm