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

8/3 복습(보충필요)

by woohyun22 2018. 8. 4.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Tiger{
    void func01() {
        System.out.println(3);
    }
}
public class Hello2 {
 
    public static void main(String[] args) {
 
         System.out.println(1);
         Tiger tiger = new Tiger();
         tiger.func01();
         System.out.println(2);
         
    }
 
}
cs



http://commin.tistory.com/106 abstract 와 interface차이점



http://zbomoon.tistory.com/13

//Thread 클래스를 사용하면 순서가 뒤죽박죽이다.




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
package prj99;
class Tiger extends Thread{
    @Override
    public void run() {
        System.out.println("999");
        for (int i = 0; i < 100; i++) {
            System.out.println("사자"+i);
        }
    }
}
class Dog{
    void start() {
        run();
    }
    void run() {
        System.out.println("run 되었다.");
    }
}
public class hello {
    public static void main(String[] args) {
        /*Dog dog = new Dog();
        dog.func01();*/
        //Thread 클래스를 사용하면 순서가 뒤죽박죽이다.?
        /*System.out.println("프로그램 시작");//아예 전부랜덤인가? ㅇ
        Tiger t1 = new Tiger();
        // start 함수는 반드시 run 함수를 콜 한다.
        t1.start();
        for (int i = 0; i < 100; i++) {
            System.out.println("호랑이"+i);
        }
        System.out.println("프로그램 끝");    
*/
        /*------------------------------------------------------------------------------*/
 
        //일반 클래스로 만들면 순서가 그대로 나온다.
        System.out.println("프로그램 시작");
        Dog d1 = new Dog();
        d1.start();
        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
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
package prj99;
class Animal{
    void func01() {
        System.out.println("부모함수1");
    }
}
class Tiger extends Animal{
    void func01() {
        System.out.println("자식함수1");
    }
}
class Cat extends Thread{
    @Override
    public void run() {
        System.out.println("Thread 작동 1");
        super.run();
    }
}
public class hello {
    public static void main(String[] args) {
        Tiger t1 = new Tiger();
        t1.func01();
        // 익명 클래스를 만들어서 사용할 수 있다. 위에 것과 같다.
        /*Animal a1 = new Animal() {
            @Override
            void func01() {
                System.out.println("익명 클래스의 함수 1");
            }
        };*/
        Animal a1 = new Animal() {
            @Override
            void func01() {
                // TODO Auto-generated method stub
                System.out.println("익명 클래스의 함수 1");
            }
        };//객체생성후 ;대신 {를 열고 바로 ctrl space 생성
        a1.func01();
        /*------------------------------------------------------------------------------*/    
        Cat c1 = new Cat();
        c1.start();//cat run으로
 
        /*Thread th = new Thread() {
            @Override
            public void run() {
                System.out.println("Thread 작동 2");
                super.run();
            }
        };*/
        Thread th1 = new Thread() {
            @Override
            public void run() {
                // TODO Auto-generated method stub
            System.out.println("thread 작동2");
            }
        };
        th1.start();
 
    }
 
}
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
package prj99;
class MyThread extends Thread{
    @Override
    public void run() {
        System.out.println("처음 예제");
    }
}
 
class KongThread implements Thread{
    public void run() {
        System.out.println("4");    
    }
}
public class hello {
    public static void main(String[] args) {
        MyThread n1 = new MyThread();
        n1.start();
        Thread n2 = new Thread() {
            @Override
            public void run() {
                System.out.println(2);
            }
        };
        n2.start();
        new Thread() {
            public void run() {
                System.out.println("세번쨰");
            }
        }.start();
 
        KongThread kong = new KongThread();
        //
        Thread n3 = new Thread(kong);
        n3.start();
 
        MyThread n5 = new MyThread();
        n5.start();
        try {
            Thread.sleep(3000);
        } catch (Exception e) {
 
        }
        System.out.println("앵무새");
        //n5.start();  thread는 start를 한번이상 쓸수없다.
        //n5.stop();//함수가 사라졌다.쓰지마라 deprecation    
    }//thread 1,2,3은 쓰자
}
cs



오류잡기 인터페이스, 상속 차이 확실하게

728x90

'비트 장기 > JAVA' 카테고리의 다른 글

8/7 (8/4에 이어서 기본 예제 형식)  (0) 2018.08.07
8/1,8/2 복습 배운거 정리하기.  (0) 2018.08.06
7/19 복습(overriding, 다형성,상)  (0) 2018.07.26
7/24 복습  (0) 2018.07.25
7/24 배움  (0) 2018.07.24

댓글