//생성자 클래스간 함수이름 대문자 인수 소문자
}
}
//생성자 지우고 오른쪽클릭 source ->construct ->super class
// check generate->생성해줌
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 32 33 34 | package pack01; class Tiger{ int a,b,c; Lion lion; Tiger(Lion lion){ System.out.println("호랑이 생성"); this.lion = lion; } void func01() { } void func02() { lion.func03(); } void func04() { lion.func03(); } } class Lion{ int a,b,c; Lion(){ System.out.println("사자 생성자 콜"); } void func03() { System.out.println("함수3번콜"); } } public class Hello { public static void main(String[] args) { Tiger t1 = new Tiger(new Lion()); t1.func02(); t1.func04(); } } | cs |
사자가먼저출력 출력순서
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 32 33 34 | package pack01; class Tiger{ int a,b,c; Tiger(){ System.out.println("생성자 콜"); } } public class Hello { //타입 = 대입 , 객체 = 공유 public static void main(String[] args) { Tiger 현성 = new Tiger(); 현성.a=10; System.out.println(현성); Tiger 멋쟁이; 멋쟁이 = 현성; System.out.println(멋쟁이); System.out.println(멋쟁이.a); 멋쟁이.a = 100; System.out.println(현성.a ); Tiger 성민 = new Tiger(); System.out.println(성민); 멋쟁이=성민; System.out.println(멋쟁이); Tiger 곰돌이; 곰돌이 =멋쟁이; System.out.println(곰돌이); 현성=곰돌이; System.out.println(현성); 성민 = new Tiger(); System.out.println(성민); System.out.println(곰돌이); } } | cs |
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 | package pack01; class Tiger{ int a,b,c; void func01(Lion lion) {//=new Lion();[Lion lion = new Lion();] System.out.println(lion); } } class Lion{ int a,b,c; } public class Hello { //타입 = 대입 , 객체 = 공유 public static void main(String[] args) { Tiger t1 = new Tiger(); t1.func01(new Lion());//()괄호 넣자!lion-PACK01.Lion@1560810 t1.func01(new Lion());// lion-PACK01.Lion@25154f System.out.println("-----"); Lion l1 = new Lion(); System.out.println(l1);//PACK01.Lion@10dea4e t1.func01(l1);//PACK01.Lion@10dea4e t1.func01(l1);//PACK01.Lion@10dea4e Lion l2; l2=l1;//l1이랑l2은 같은인물 System.out.println(l2);//PACK01.Lion@10dea4e t1.func01(l1);//PACK01.Lion@10dea4e t1.func01(l2);//PACK01.Lion@10dea4e } } | cs |
728x90
'비트 장기 > JAVA' 카테고리의 다른 글
7/23 (exception 예외처리 try catch) (0) | 2018.07.23 |
---|---|
7/21 배움 (추상class, ) (0) | 2018.07.21 |
7/19 배움(상속, overriding, 다형성 ) (0) | 2018.07.19 |
7/18 복습 (0) | 2018.07.19 |
7/18 배움(함수,overloading, 생성자 class, chaining, final, static) (0) | 2018.07.18 |
댓글