classMyThreadimplementsRunnable{
//创建线程类
public void run() {
System.out.println("Thread body");
}
}
public class Test{
public static void main(String[] args){
MyThread thread = new MyThread();
Thread t = new Thread(thread);
t.start();//开启线程
}
}
2.继承Thread类,重写run方法
classMyThreadextendsThread {
public void run() {
System.out.println("Thread body");
}
}
public classTest {
public static void main(String[] args) {
Mythread thread = new MyThread();
thread.start();
}
}
三、利用递归方法实现6!
public classTest {
public static long fac(int n){
if(n > 1)
return (n*fac(n-1));
elsereturn1;
}
public static void main(String[] args) {
System.out.println(fac(6));
}
}