代码如下:public class MyThread2 implements Runnable
{
public static void main(String[] args)
{
Thread t = Thread.currentThread();
System.out.println("当前线程是:" + t);
t.setName("JavaThread");
System.out.println("当前线程名是:" + t); MyThread2 thread2 = new MyThread2();
thread2.start();
} public void run()
{
System.out.println("子线程是:" + this);
}
}
抱错信息如下:MyThread2.java:10:找不到符号
符号: 方法 start();
位置: 类 MyThread2
thread2.start();
^
1 错误我实在搞不懂了,我觉得明明是对的啊!怎么会抱那个错啊
{
public static void main(String[] args)
{
Thread t = Thread.currentThread();
System.out.println("当前线程是:" + t);
t.setName("JavaThread");
System.out.println("当前线程名是:" + t); MyThread2 thread2 = new MyThread2();
thread2.start();
} public void run()
{
System.out.println("子线程是:" + this);
}
}
抱错信息如下:MyThread2.java:10:找不到符号
符号: 方法 start();
位置: 类 MyThread2
thread2.start();
^
1 错误我实在搞不懂了,我觉得明明是对的啊!怎么会抱那个错啊
Thread thread2 = new Thread(new MyThread2());
thread2.start();
public class MyThread2 extends Thread {
public static void main(String[] args)
{
Thread t = Thread.currentThread();
System.out.println("当前线程是:" + t);
t.setName("JavaThread");
System.out.println("当前线程名是:" + t); MyThread2 thread2 = new MyThread2();
thread2.start();
} public void run() {
System.out.println("子线程是:" + this);
}
}
这样不行吗
==〉
public class MyThread2 extends Thread这样也可以,呵呵!不过应该按照前面几位的更好。
public static void main(String[] args) {
Thread t = Thread.currentThread();
System.out.println("当前线程是:" + t);
t.setName("JavaThread");
System.out.println("当前线程名是:" + t); MyThread2 thread2 = new MyThread2();
Thread thread=new Thread(thread2);
thread.start();
} public void run() {
System.out.println("子线程是:" + this);
}
}这样咯是么?
昨天才注册的。。现在在努力学习java,准备去北京混
今年就毕业了,迷茫咯~!