Java 싱글턴

1 개요[ | ]

Java Singleton
Java 싱글턴
public class App {
    public static void main(String[] args) {
        methodA();
        methdoB();
    }

    private static void methodA() {
        MusicPlayer musicPlayer = MusicPlayer.getInstance();
        System.out.println(musicPlayer);
    }

    private static void methdoB() {
        MusicPlayer musicPlayer = MusicPlayer.getInstance();
        System.out.println(musicPlayer);
    }

}

class MusicPlayer {
    private static final MusicPlayer instance = new MusicPlayer();

    private MusicPlayer() {
    }

    public static MusicPlayer getInstance() {
        return instance;
    }
}

2 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}