티스토리 뷰
public class Main {
public static void main(String[] args) {
Thread th = new Thread(new MyThread());
th.start();
for(int i = 0; i < 30; i ++) {
System.out.println("메인");
try {
Thread.sleep(10);
}catch(InterruptedException e) {
e.printStackTrace();
}
}
}
}
`
//상속도 받고 쓰레드도 쓰고 싶을 때 Runnable을 씀
public class MyThread extends Person implements Runnable {
public void run() {
name= "하이";
for (int i = 0; i< 30; i++) {
System.out.println("쓰레드");
try {
Thread.sleep(10);
}catch(InterruptedException e) {
e.printStackTrace();
}
}
}
}
ㅁ
public class Person {
int age;
String name;
}
'JAVA' 카테고리의 다른 글
GoldenGoose_멀티스레드 연습 (0) | 2020.09.03 |
---|---|
Sep2_프레임창 화면 중앙에 위치시키기(AWT, JFrame) (0) | 2020.09.03 |
파일저장_Stream (0) | 2020.08.31 |
상속_오버라이딩, Final, 다형성, 추상클래스, 추상메소드 (0) | 2020.08.18 |
SimpleGame_모범 (0) | 2020.08.18 |
댓글