JAVA 단일 디자인

563 단어
package org.classdemo;

class Single{
    private static Single instance = new Single();
    private Single(){
        
    }
    
    public static Single getInstance(){
        return instance;
    }
    
    public void print(){
        System.out.println("Hello World!!");
    }
}

public class SingleDemo {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Single s = null;
        s = s.getInstance();
        s.print();
    }

}

좋은 웹페이지 즐겨찾기