728x90
아래 2개의 클래스파일을 작성하고, 메인에서 아래와 같은 실행결과가 나오도록 코딩하시오.
SmartPhone<C, M, I>클래스
멤버변수
private ? company
private ? model
private ? inch
멤버함수
생성자 구현
getter, setter
SmarthPhoneExample1(실행클래스)
실행화면
결과
<String, String, Double> 객체 생성 후 저장 값 불러오기
회사 : Samsung
모델 : 갤럭시5
인치 : 5.5
<String, String, String> 객체 생성 후 저장 값 불러오기
회사 : LG전자
모델 : V20
인치 : 6.0
코드
class SmartPhone2<C, M, I> {
private C company;
private M model;
private I inch;
public SmartPhone2() {
}
public void setData(C company, M model, I inch) {
this.company = company;
this.model = model;
this.inch = inch;
}
public C getCompany() {
return company;
}
public M getModel() {
return model;
}
public I getinch() {
return inch;
}
}
public class SmartPhoneExample1 {
public static void main(String[] args) {
System.out.println("<String, String, Double> 객체 생성 후 저장 값 불러오기");
SmartPhone2<String, String, Double> samsungPhone = new SmartPhone2<>();
samsungPhone.setData("Samsung", "갤럭시5", 5.5);
System.out.println("회사 : " + samsungPhone.getCompany());
System.out.println("모델 : " + samsungPhone.getModel());
System.out.println("인치 : " + samsungPhone.getinch());
System.out.println();
System.out.println("<String, String, String> 객체 생성 후 저장 값 불러오기");
SmartPhone2<String, String, String> LGPhone = new SmartPhone2<>();
LGPhone.setData("LG전자", "V20", "6.0");
System.out.println("회사 : " + LGPhone.getCompany());
System.out.println("모델 : " + LGPhone.getModel());
System.out.println("인치 : " + LGPhone.getinch());
}
}728x90
'Java' 카테고리의 다른 글
| [Java] 제네릭 클래스 예제 (20-5 확인 필요) (0) | 2023.09.07 |
|---|---|
| [Java] 제네릭 클래스 예제 (20-4) (0) | 2023.09.07 |
| [Java] 제네릭 클래스 예제 (20-2) (0) | 2023.09.07 |
| [Java] 제네릭 클래스 예제 (20-1) (0) | 2023.09.07 |
| [Java] 제네릭 클래스 예제 (검토 필요) (0) | 2023.09.02 |