Java/basic
004 사용자 참조 타입
junmoyo
2022. 4. 20. 15:19
description :
사용자 정의 참조 타입을 선언하여 사용해보자.
source code : exam004.java
package exam004;
class MyRefer {
private int id;
private double height;
private double width;
MyRefer(){
}
public int GetId() {
return this.id;
}
public void SetId(int id) {
this.id = id;
}
public double GetHeight() {
return this.height;
}
public void SetHeight(double height) {
this.height = height;
}
public double GetWidth() {
return this.width;
}
public void SetWidth(double width) {
this.width = width;
}
}
public class exam004 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int myId = 1234;
double myHeight = 100.0f;
double myWidth = 100.0f;
System.out.println("클래스 선언및 인스턴스 생성");
MyRefer myRefer = new MyRefer();
System.out.println("인스턴스 생성 완료");
System.out.println("초기회 되지 않은 값 출력");
System.out.println("myRefer : " + myRefer + '\n' +
"myRefer.GetId() : " + myRefer.GetId() + '\n' +
"myRefer.GetWidth() : " + myRefer.GetWidth() + '\n' +
"myRefer.GetHeight() : " + myRefer.GetHeight());
System.out.println('\n'+"값 셋팅후 출력 않은 값 출력");
myRefer.SetId(myId);
myRefer.SetWidth(myWidth);
myRefer.SetHeight(myHeight);
System.out.println("myRefer : " + myRefer + '\n' +
"myRefer.GetId() : " + myRefer.GetId() + '\n' +
"myRefer.GetWidth() : " + myRefer.GetWidth() + '\n' +
"myRefer.GetHeight() : " + myRefer.GetHeight());
System.out.println("\n만들어진 객체 newMyRefer에 값 넘긴후 출력");
MyRefer newMyRefer = myRefer;
System.out.println("myRefer : " + newMyRefer + '\n' +
"myRefer.GetId() : " + newMyRefer.GetId() + '\n' +
"myRefer.GetWidth() : " + newMyRefer.GetWidth() + '\n' +
"myRefer.GetHeight() : " + newMyRefer.GetHeight());
}
}
result :