Java
Thread 상속으로 thread 생성
Eddy Jo
2017. 1. 27. 13:55
Thread 클래스를 상속받아 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 | public class CreateThread2 { /* Thread클래스를 상속받은 하위 클래스를 통한 thread 생성 */ public static void main(String[] args) { //직접 클래스를 정의해 Thread 생성 Thread thread = new SubThread(); thread.start(); //익명 클래스로 Thread 생성 Thread thread2 = new Thread() { public void run() { System.out.println("Anonymous thread"); } }; thread2.start(); } public static class SubThread extends Thread { public void run() { //thread 실행시 실행될 부분 System.out.println("Thread 하위클래스로 생성"); } } } | cs |