일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- angular2
- 이클립스
- 상속예제
- 전체텍스트
- jquery
- 스프링
- 자바
- 로또
- 업캐스팅
- 추상클래스
- 다형성
- 페이징
- Full text
- 자바 야구게임
- 가변인자
- 상속
- 전체
- Login with OAuth Authentication
- full text indexing
- Random
- 형변환
- IBatis procedure
- 전자정부
- 25가지 효율적인 sql작성법
- 다운캐스팅
- Validations
- 야구게임
- while
- 단축키
Archives
- Today
- Total
nalaolla
오브젝트 예제 5 본문
728x90
반응형
- package test.com;
- public class Test04Car {
- String kind;
- int year;
- String num;
- int doorCount;
- public Test04Car() {
- kind = "승용차";
- year = 2015;
- num = "11가1234";
- doorCount = 4;
- }
- public Test04Car(String kind, int year, String num, int doorCount) {
- this.kind = kind;
- this.year = year;
- this.num = num;
- this.doorCount = doorCount;
- }
- }
- package test.com;
- public class Test05BBB {
- Test04Car c;
- Test04Car[] cs;
- public Test05BBB() {
- c = new Test04Car();
- cs = new Test04Car[3];
- cs[0] = new Test04Car();
- cs[1] = new Test04Car("aaa", 1111, "bbbb", 22);
- cs[2] = new Test04Car("ccc", 444, "ddd", 555);
- }
- public Test05BBB(Test04Car c, Test04Car[] cs) {
- this.c = c;
- this.cs = cs;
- }
- public Test05BBB(Test04Car[] cs) {
- this.cs = cs;
- for (Test04Car c : cs) {
- System.out.print(c.kind + " ");
- System.out.print(c.year + " ");
- System.out.print(c.num + " ");
- System.out.println(c.doorCount);
- }
- }
- public Test05BBB(Test04Car c) {
- this.c = c;
- }
- }
- package test.com;
- public class Test04CarMain {
- public static void main(String[] args) {
- System.out.println("Car...");
- String line = "================================";
- Test04Car c01 = new Test04Car();
- System.out.println(c01.kind);
- System.out.println(c01.year);
- System.out.println(c01.num);
- System.out.println(c01.doorCount);
- System.out.println(line);
- Test04Car c02 = new Test04Car("승합", 2012, "33삼3333", 3);
- System.out.println(c02);
- System.out.println(c02.kind);
- System.out.println(c02.year);
- System.out.println(c02.num);
- System.out.println(c02.doorCount);
- System.out.println(line);
- //c01, c02를 이용하여 배열생성 및 출력
- Test04Car[] cs = new Test04Car[]{c01, c02};
- System.out.println("차종 연식 차번호 도어수");
- /*
- for (int i = 0; i < cs.length; i++) {
- //System.out.println(cs[i]);
- System.out.print(cs[i].kind + " ");
- System.out.print(cs[i].year + " ");
- System.out.print(cs[i].num + " ");
- System.out.print(cs[i].doorCount + " ");
- System.out.println();
- }*/
- for (Test04Car c : cs) {
- System.out.print(c.kind + " ");
- System.out.print(c.year + " ");
- System.out.print(c.num + " ");
- System.out.println(c.doorCount);
- }
- System.out.println("=========== Test05BBB =============");
- Test05BBB b01 = new Test05BBB();
- System.out.print(b01.c.kind);
- System.out.print(b01.c.year + " ");
- System.out.print(b01.c.num + " ");
- System.out.println(b01.c.doorCount);
- System.out.println(b01.cs.length);
- for (int i = 0; i < b01.cs.length; i++) {
- System.out.println(b01.cs[i]);
- System.out.println(b01.cs[i].kind);
- System.out.println(b01.cs[i].year);
- System.out.println(b01.cs[i].num);
- System.out.println(b01.cs[i].doorCount);
- }
- System.out.println("=========== Test05BBB =============");
- Test05BBB b02 = new Test05BBB(cs);
- System.out.println(b02);
- } //end main
- } //end class
728x90
반응형
'JAVA > 6. Object2' 카테고리의 다른 글
오브젝트 예제 3 (class와 class 이용하여 배열처리) (0) | 2016.06.22 |
---|---|
오브젝트 예제 2 (배열활용) (0) | 2016.06.22 |
오브젝트 예제 1 (0) | 2016.06.22 |