黑马程序员技术交流社区
标题:
用Thread父类的构造方法的时候编译出错;求帮助
[打印本页]
作者:
曾林魁
时间:
2013-5-25 17:49
标题:
用Thread父类的构造方法的时候编译出错;求帮助
本帖最后由 曾林魁 于 2013-5-30 12:20 编辑
class ThreadDemo1 extends Thread
{
void ThreadDemo1(){}
void ThreadDemo1(String name)
{
super(name);
}
public void run()
{
for (int i = 0;i<=100 ;i++ )
{
System.out.println(this.getName()+"this is a instance of thread");
}
}
public static void main(String[] args)
{
ThreadDemo1 t1= new ThreadDemo1("线程1");
ThreadDemo1 t2= new ThreadDemo1("线程2");
//ThreadDemo1 t1= new ThreadDemo1();
//ThreadDemo1 t2= new ThreadDemo1();
t1.start();
t2.start();
System.out.println("Hello World!");
}
}
复制代码
编译提醒无法调用构造器怎么回事?
作者:
王靖远
时间:
2013-5-25 17:56
class ThreadDemo1 extends Thread
{
void ThreadDemo1(){}//void 去掉
void ThreadDemo1(String name)//void去掉
{
super(name);
}
public void run()
{
for (int i = 0;i<=100 ;i++ )
{
System.out.println(this.getName()+"this is a instance of thread");
}
}
public static void main(String[] args)
{
ThreadDemo1 t1= new ThreadDemo1("线程1");
ThreadDemo1 t2= new ThreadDemo1("线程2");
//ThreadDemo1 t1= new ThreadDemo1();
//ThreadDemo1 t2= new ThreadDemo1();
t1.start();
t2.start();
System.out.println("Hello World!");
}
}
复制代码
作者:
simonqian
时间:
2013-5-25 17:59
本帖最后由 simonqian 于 2013-5-25 18:01 编辑
class ThreadDemo1 extends Thread
{
ThreadDemo1(){}
ThreadDemo1(String name)
{
super(name);
}
public void run()
{
for (int i = 0;i<=100 ;i++ )
{
System.out.println(this.getName()+"this is a instance of thread");
}
}
public static void main(String[] args)
{
ThreadDemo1 t1= new ThreadDemo1("线程1");
ThreadDemo1 t2= new ThreadDemo1("线程2");
//ThreadDemo1 t1= new ThreadDemo1();
//ThreadDemo1 t2= new ThreadDemo1();
t1.start();
t2.start();
System.out.println("Hello World!");
}
}
复制代码
构造方法是不需要返回类型的
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2