java代码帮忙看看哪里出错了?

来源:百度知道 编辑:UC知道 时间:2024/07/03 03:29:57
class TestThread
{
public static void main(String[] args)
{
Thread1 t1=new Thread1();
t1.start();
t1.stopThread();
int index=0;
while(true)
{
if(500==index++)
{
break;
}
System.out.println(Thread.currentThread.getName());;
}
}
}
class Thread1 extends Thread
{
private boolean bStop=false;
public void run()
{
while(!bStop)
{
System.out.println(getName);
}
}
public void stopThread()
{
bStop=true;
}
}
错误信息:
符号: 方法 start()
位置: 类 Thread1
t1.start();
^
TestThread.java:15: 找不到符号
符号: 变量 currentThread
位置: 类 Thread
System.out.println(Thread.currentThread.getName());;
^
TestThread.java:26: 找不到符号
符号: 变量 getName
位置: 类 Threa

方法后面要写括号,具体看标注位置

class TestThread
{
public static void main(String[] args)
{
Thread1 t1=new Thread1();
t1.start();
t1.stopThread();
int index=0;
while(true)
{
if(500==index++)
{
break;
}
System.out.println(Thread.currentThread().getName());; //currentThread后面没写括号
}
}
}
class Thread1 extends Thread
{
private boolean bStop=false;
public void run()
{
while(!bStop)
{
System.out.println(getName()); //getName后面没写括号
}
}
public void stopThread()
{
bStop=true;
}
}

class TestThread {
public static void main(String[] args) {
Thread1 t1 = new Thread1();
t1.start();
t1.stopThread();
int index = 0;
while (true) {
if (500 == index++) {
break;
}
System.out.println(Thread.currentThread().getName());
}
}
}<