//Problem:Limit the instance of a class to one.
class Runtime{
private static Runtime r;
private Runtime(){
System.out.println("In Runtime class.");
}
static{
r=new Runtime();
}
static Runtime getRuntime(){
Runtime r=new Runtime();
return r;
}
}
class TestRuntime{
public static void main(String[] args) {
Runtime r1;
r1=Runtime.getRuntime();
}
}
I want to understand what this code actually does, and how it limits the object creation. What could be the other possible solutions? Preferably in a manner this code solves the problem.