Tags

, ,

public abstract class CallAbstractClass {

public static CallAbstractClass getInstance()    {return new HiddenClass();}
public abstract String print();

public static void main(String[] args) {
CallAbstractClass instance = CallAbstractClass.getInstance();
System.out.println(instance.print());
}
}

class HiddenClass extends CallAbstractClass    {
public HiddenClass()  {    }
public String print() {  return “Yeah”;  }
}

– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
Concept : Singleton

class Singleton  {

  private static Singleton instance = null;

  private Singleton() { ... }

  public static Singleton getInstance() {
     if (instance==null){
           instance = new Singleotn();
     }
     return instance;
  }

  public void otherMethod()  { ... }

}
Advertisements