# 각국 통화 화폐 정답예시에서 currency 생성자를 public으로 선언해주는 이유는 뭔가요? #### CODE <a class='btn btn-default' href='/codes/25185'>Link</a> ``` public class Main { public static void main(String[] args) { // 객체 생성 KRW krw = new KRW(1500, "원"); USD usd = new USD(100.50, "달러"); EUR eur = new EUR(260.87, "유로"); JPY jpy = new JPY(1400, "엔"); // 부모 클래스를 통한 그룹화 Currency[] currencies = { krw, usd, eur, jpy }; // 모든 화폐정보를 출력 for (Currency c : currencies) { System.out.println(c.toString()); } } } /* 1. 부모 클래스 Currency를 만드시오. */ /* 2. 상속을 통해 중복 코드를 제거 후, */ /* 3. 생성자를 올바르게 수정하시오. */ /* 4. toString() 메소드를 오버라이딩 하시오. */ class Currency { protected double amount; // 수량(1000) protected String notation; // 표기법(원) Currency(double amount, String notation) { this.amount = amount; this.notation = notation; } public String toString() { return String.format("화폐 : 원"); } } class KRW extends Currency { public KRW(double amount, String notation) { super(amount, notation); } public String toString() { return String.format("KRW: %.2f 원", super.amount); } } class USD extends Currency { public USD(double amount, String notation) { super(amount, notation); } public String toString() { return String.format("USD: %.2f 달러", super.amount); } } class EUR extends Currency { public EUR(double amount, String notation) { super(amount, notation); } public String toString() { return String.format("EUR: %.2f 유로", super.amount); } } class JPY extends Currency { public JPY(double amount, String notation) { super(amount, notation); } public String toString() { return String.format("JPY: %.2f 엔", super.amount); } } ``` #### INPUT ``` ``` #### OUPUT ``` KRW: 1500.00 원 USD: 100.50 달러 EUR: 260.87 유로 JPY: 1400.00 엔 ```
# 생성자의 접근 제한자 큰 의미는 없습니다만, 생성자는 일반적으로 public을 사용합니다 ## PS. 질문 감사합니다!