티스토리 뷰
package day160708;
class robotInfo{
String model, lang;
int since, working;
robotInfo(String model, int since, int working, String lang){
this.model = model;
this.since = since;
this.working = working;
this.lang = lang;
this.robotInfoPrint();
}
void robotInfoPrint(){
System.out.println("=-=-=-=-= INFO =-=-=-=-=");
System.out.println("Model : " + this.model);
System.out.println("DEV_lang : " + this.lang);
System.out.println("Since : " + this.since);
System.out.println("working : " + this.working + "족 보행");
System.out.println("=-=-=-=-=-=-=-=-=-=-=-= \n");
}
}
public class day160708_02 {
public static void main(String[] args) {
robotInfo atlas = new robotInfo("ATLAS SC01", 2158, 2, "JAVA");
robotInfo pbody = new robotInfo("pbody", 2169, 2, "C");
robotInfo dog = new robotInfo("DOG", 2011, 4, "Python");
}
}
=-=-=-=-= INFO =-=-=-=-=
Model : ATLAS SC01
DEV_lang : JAVA
Since : 2158
working : 2족 보행
=-=-=-=-=-=-=-=-=-=-=-=
=-=-=-=-= INFO =-=-=-=-=
Model : pbody
DEV_lang : C
Since : 2169
working : 2족 보행
=-=-=-=-=-=-=-=-=-=-=-=
=-=-=-=-= INFO =-=-=-=-=
Model : DOG
DEV_lang : Python
Since : 2011
working : 4족 보행
=-=-=-=-=-=-=-=-=-=-=-=
이 예제를 통해서 객체지향 프로그래밍 기법의 장점을 확실히 볼 수 있는데요.
단지, 인스턴스를 생성할때 인자값을 줌으로써 편리하게 로봇들의 정보를 볼 수 있습니다.
클래스로 기본 틀을 짜두고, 그에 맞게 값만 집어넣으면 오류없이 작동하는모습을 볼 수 있습니다.
인스턴스를 생성할때 생성 즉시 생성자인 robotInfo 메소드로 달려간후, 변수값을 저장한다음에
바로 robotInfoPrint 메소드를 실행하는것을 볼 수 있습니다.
'Java' 카테고리의 다른 글
자바 this 문 을 사용한 심화 예제 (0) | 2016.07.08 |
---|---|
자바 생성자 예제 (0) | 2016.07.08 |
자바 메소드 오버로딩 예제 [2] (0) | 2016.07.07 |
자바 메소드 오버로딩 예제 (0) | 2016.07.07 |
자바 return 문과 인자값 받기 예제 (0) | 2016.07.07 |