class ThreadInherit extends Helper implements Runnable
{
@Override
public void run() {
// TODO Auto-generated method stub
try {
for (int i = 1; i <= 20; i++) {
System.out.println("Hello World");
Thread.sleep(500);
if (i == 10) {
Notify();
Wait();
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
class Thread_Inherit1 extends ThreadInherit
{
@Override
public void run() {
// TODO Auto-generated method stub
try {
Wait();
for(int i = 1; i<=20; i++)
{
System.out.println("Welcome");
Thread.sleep(550);
}
Notify();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
class Helper
{
public synchronized void Wait() throws InterruptedException
{
wait();
}
public synchronized void Notify() throws InterruptedException
{
notify();
}
}
public class Inheritance_Class {
public static void main (String[] args)
{
Thread_Inherit1 u = new Thread_Inherit1();
Thread_Inherit1 t = new ThreadInherit();
t.run();
u.run();
}
}
所以我有这段代码......我对这条线有疑问
Thread_Inherit1 t = new ThreadInherit();
它不能转换为 Thread_Inherit1。Eclipse的建议:
1.将强制转换添加到 Thread_Inherit1(我做了,但仍然给我错误) 2.更改为 ThreadInherit。(可能,不是解决方案)
有什么帮助吗?