본문 바로가기
비트 장기/JAVA

7/18 복습

by woohyun22 2018. 7. 19.


alt shift r


인수는 항상 대입연산이 나타난다. 인수 전달


cn a = new cn;


void func06(Apple aa) {// cn a = new cn class name
        System.out.println("소나무");
        func01();
        aa.func01();//Apple class의 함수를 가져온다.
    }



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
35
36
37
38
39
package practice1;
class Tiger{
    int a,b,c;
    Tiger(){
        System.out.println("call");
    }
    void func01() {
        System.out.println("호랑이");
    }
    void func02() {
        System.out.println("코끼리");
    }
    int func03() {
        System.out.println("앵무새");
        return 1;//리턴값 날아가버림
    }
    int func04(int a,int b)
    {
        int c=a+b;
        System.out.println("낙타"+" "+c);
        return c;
    }
    void func05(String s) {
        System.out.println(s);
    }
}
public class practice1 {
    public static void main(String[] args) {
        Tiger t1 = new Tiger();
        t1.func01();
        t1.func02();
        t1.func03();
        t1.func04(2,3);
        t1.func05("개똥지빠귀");//호출에 바로 적거나
        String s = new String("호랭이");//객체생성후 적기 두가지
        t1.func05(s);
    }
}
 
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package practice1;
class Apple{//class에는 () x
    int a,b,c;
    Apple(){
        System.out.println("Apple call");
    }
    void func01() {
        System.out.println("Apple의 함수 1");
    }
}
class Tiger{
    int a,b,c;
    Tiger(){
        System.out.println("Tiger call");
    }
    void func01() {
        System.out.println("호랑이");
    }
    void func02(int a) {
        System.out.println("코끼리");
    }
    int func03() {//int 일때 return
        System.out.println("앵무새");
        return 1;
    }
    int func04(int a,int b) {
        System.out.println("낙타"+" "+(a*b));
        return a*b;
    }
    void func05(String s) {
        System.out.println(s);
    }
    void func06(Apple aa) {//Apple class의 함수를 끌어 쓸수있음
        System.out.println("소나무");
        aa.func01();//인수명과 같이
    }
}
public class practice1 {
    public static void main(String[] args) {
        Apple a1 = new Apple();
        Tiger t1 = new Tiger();
        a1.func01();//생성자가 먼저돈다.
        t1.func01();
        t1.func02(3);
        t1.func03();
        t1.func04(3,4);
        t1.func05("신사동호랭이");
        t1.func06(new Apple());//함수 호출에서 다른 클래스를 끌어낼때 쓰는방법
        t1.func06(a1);//같은 방법
        
    }
}
 
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package practice;
class Apple{
    int a,b,c;
    Apple(){
        System.out.println("call");
    }
    void func01() {
        System.out.println("맛있는 사과");
    }    
}
class Banana{
    int a,b,c;
    Banana(){
        System.out.println("call");
    }
    void func01() {
        System.out.println("맛있는 사과");
    }
}
class Orange{
    int a,b,c;
    Orange(){
        System.out.println("call");
    }
    void func01() {
        System.out.println("맛있는 사과");
    }
}
class Tiger{
    int a,b,c;
    Tiger(){
        System.out.println("call ");
    }
    void func01(Apple a2) {
        System.out.println("호랑이가 ");
        a2.func01();
        System.out.println("먹습니다.");
    }
    void func02(Banana a2) {
        System.out.println("호랑이가 새끼가");
        a2.func01();
        System.out.println("먹습니다.");
    }
    void func03(Orange a2) {
        System.out.println("호랑이가 엄마가");
        a2.func01();
        System.out.println("먹습니다.");
    }
}
public class practice {
    public static void main(String[] args) {
        Apple a1 = new Apple();
        Tiger t1 = new Tiger();
        Orange o1 = new Orange();
        Banana b1 = new Banana();
        t1.func01(a1);
        t1.func02(b1);
        
        
    }
}
 
 
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package practice;
 
import java.util.Random;
 
class Apple{
    int a,b,c;
    Apple(){
        System.out.println("call");
    }
    void func01() {
        System.out.println("호랑이");
    }
    void func02() {
        System.out.println("코끼리");
    }
    void func03() {
        System.out.println("앵무새");
    }
    int func04() {
        int a = 100;
        return a;
    }
    String func05() {
        String s = "낙타";
        return s;
    }
    Apple func06() {
        System.out.println("난 6번");
        return this;
    }
    Apple func07() {
        System.out.println("난 7번");
        return this;
    }
    Apple func08() {
        System.out.println("난 8번");
        return this;
    }
}
public class practice {
    public static void main(String[] args) {
        Apple a1 = new Apple();
        int i1 = a1.func04();
        System.out.println(i1);
        String s1 = a1.func05();
        System.out.println(s1);
        Apple f1 = a1.func06();
        a1.func01();
        a1.func02();
        a1.func03();
        a1.func04();
        a1.func05();
        a1.func06();
        a1.func07();
        a1.func08();
        
        a1.func06().func06().func06().func07().func01();
        new Apple().func01();
        new Random().nextInt(100);
        
    }
}
 
 
cs




728x90

댓글