dimanche 27 septembre 2020

Singleton pattern implementation. Cannot find symbol error shown [duplicate]

I was trying to implement the Singleton Pattern in a simple code.

public class Singleton {
    private static Singleton instance = null;
    private Singleton(){}
    
    public static Singleton getInstance(){
     if(instance == null){
      instance = new Singleton();
     }
     return instance;
    }
    
    public void op(){
    System.out.print("Works");
    }
    
}

public class Prove {

   
    public static void main(String[] args) {
        Singleton singleton = instance.getInstance();
        singleton.op();
    }
    
}

It keeps showing a cannot find symbol error. I was wondering why this happens

Aucun commentaire:

Enregistrer un commentaire