JAVA_32_스레드 상속

hyeong taek jo·2023년 7월 15일

JAVA

목록 보기
32/39
class ThreadExample2 extends Thread {
	
	@Override
	public void run() {
		for (int i = 1 ; i <= 20 ; i ++) {
			System.out.print("대박 " + i + " \t");
			if(i%5==0) System.out.println();
			try {
				sleep(50); // 0.5초씩 // 1000분의 50 초씩 쉬고
			} catch (InterruptedException e) {
				
			}
		}
	}
}


class ThreadExample3 extends Thread {
	@Override
	public void run() {
		for (int i = 1 ; i <= 20 ; i ++) {
			System.out.print("화요일 " + i + "\t");
			if(i%5==0) System.out.println();
			try {
				sleep(100); // 1초씩 // 1000분의 100초씩 쉬고
			} catch (InterruptedException e) {
				
				
			}
		}
	}
}


public class ThreadTest3 {

	public static void main(String[] args) {
		ThreadExample2 te2 = new ThreadExample2();
		ThreadExample3 te3 = new ThreadExample3();
		te2.start();
		te3.start();
		
	}

}

대박 1 화요일 1 대박 2 화요일 2 대박 3 대박 4 화요일 3 대박 5
대박 6 화요일 4 대박 7 화요일 5
대박 8 대박 9 화요일 6 대박 10
대박 11 화요일 7 대박 12 화요일 8 대박 13 대박 14 화요일 9 대박 15
대박 16 화요일 10
대박 17 대박 18 화요일 11 대박 19 화요일 12 대박 20
화요일 13 화요일 14 화요일 15
화요일 16 화요일 17 화요일 18 화요일 19 화요일 20

profile
마포구 주민

0개의 댓글