Notice
Recent Posts
Recent Comments
Link
«   2025/09   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
Tags
more
Archives
Today
Total
관리 메뉴

UniCode

[이것이 자바다]CH06.클래스(확인문제풀이)-③ 본문

이것이 자바다

[이것이 자바다]CH06.클래스(확인문제풀이)-③

Uni_code 2021. 3. 29. 21:23

18. ShopService 객체를 싱글톤으로 만들고 싶습니다. ShopServiceExample 클래스에서 ShopService의 gerInstance( )메소드로 싱글톤을 얻을 수 있도록 ShopService 클래스를 작성해보세요.

[ShopService.java]
public class ShopService{
   // 작성 위치
}
[ShopServiceExample.java]
public class ShopServiceExample{
   public static void main(String[] args){
     ShopService obj1 = ShopService.getInstance();
     ShopService obj2 = ShopService.getInstance();
     if(obj1 == obj2){
          System.out.println("같은 ShopService 객체 입니다.");
     } else {
          System.out.println("다른 ShopService 객체 입니다.");
     }

   }
}

private static ShopService shopservice = new ShopService();

public static ShopService getInstance() {
return shopservice;
}

 

19.