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。 (可能不是解决方案)

有什么帮助吗?

最佳答案

您的代码具有:

class Thread_Inherit1 extends ThreadInherit


...而您的问题是:

Thread_Inherit1 t = new ThreadInherit();


麻烦在于事情倒退了。 ThreadInherit不是thread_Inherit1。我认为您打算写的行是:

ThreadInherit t = new Thread_Inherit1();


希望能解决您的问题。

10-05 18:36