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 |
What are different types of control structures?
there are some duplicate values in ArrayList, how U'll get that array with out duplicate?
Why do people says “java is robust”?
Can we have any code between try and catch blocks?
What is the preferred size of a component in java programming?
Does a class inherit the constructor of its super class?if it does, how can you hide that constructor? if it doesnot how can you call it from the sub class?
How is java created?
If your team member writes code with lots of static variables and static methods, will it cause any side effects?
What is difference between c++ and java ?
how are methods defined?
what is servlet filter?
What does || || mean in math?