티스토리 뷰

Java

자바 this 사용 예제

볼봇 2016. 7. 8. 22:22

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 메소드를 실행하는것을 볼 수 있습니다.


댓글
10-22 15:36
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2025/10   »
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 31
글 보관함