package com.andy.thread;
/*
* 线程实现的两种方式
* 1、继承Thread类
* 2、实现Runnable接口
*
*/
public class ThreadDemo {
public static void main(String[] args){
//继承Thread类
MyThread mythread =new MyThread();
mythread.start();
for(int a=0;a<10;a++){
System.out.println("a=="+a);
}
//实现Runnable接口
MyRunnable runnable=new MyRunnable();
Thread thread=new Thread(runnable);
thread.start();
}
}
class MyThread extends Thread{
@Override
public void run() {
for(int i=0;i<10;i++){
System.out.println("i=="+i);
}
super.run();
}
}
class MyRunnable implements Runnable{
@Override
public void run(){
for(int b=0;b<10;b++){
System.out.println("b=="+b);
}
}
}
/*
* 线程实现的两种方式
* 1、继承Thread类
* 2、实现Runnable接口
*
*/
public class ThreadDemo {
public static void main(String[] args){
//继承Thread类
MyThread mythread =new MyThread();
mythread.start();
for(int a=0;a<10;a++){
System.out.println("a=="+a);
}
//实现Runnable接口
MyRunnable runnable=new MyRunnable();
Thread thread=new Thread(runnable);
thread.start();
}
}
class MyThread extends Thread{
@Override
public void run() {
for(int i=0;i<10;i++){
System.out.println("i=="+i);
}
super.run();
}
}
class MyRunnable implements Runnable{
@Override
public void run(){
for(int b=0;b<10;b++){
System.out.println("b=="+b);
}
}
}