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 are 3 data types?
What is variable and example?
How do you get the length of a string in java?
Is java util regex pattern thread safe?
Hi all, I am dng a mini project on FileSplitter application which splits the GBs of logfile into Smaller chunks(mbs) depending on the split size." How to handle GBs file? I am getting OutOfMemoryException, when I input such GB sized file. Thx
What is this keyword used for?
What is a function easy definition?
What is a blocking method in Java?
What are computer functions?
Why multiple inheritance is not supported by java?
Can we split string with in java?
What isan abstract class and when do you use it?
What is string immutability?
What is a ternary operator in java?
What is mvc in java?