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
Can we sort array in java?
How many types of methods are there in java?
Where can i get Latest SUN Certification Dumps and what are the Sun Certification Codes that are available, Im new to JAVA, so please gimme info as i need to write J2EE - Core Java Certification
Is it possible for a yielded thread to get chance for its execution again?
How can a gui component handle its own events?
What is the difference between numeric and integer?
Why java is used everywhere?
Name few java.lang classes introduced with java 8 ?
What is native method in java?
Explain about the select method with an example?
What is a substitution variable?
What is boolean logic?
What does += mean in java?
What is a boolean structure?
give an example for encapsulation?