即使没有实现接口,程序也在编译

时间:2013-05-31 05:06:31

标签: java

我有一个名为abc

的界面
public interface abc
{
    void start();
}

我有一个名为def

的抽象类
public abstract class def extends Thread implements abc
{
}

我创建了另一个扩展名为def

ghj的类
public class ghj extends def
{
  //it is defing all the methods of its above abstract class
  //now it does not implement the method define in interface start();
}

请告知类ghj是否未实现接口abc所需的方法,那么该程序如何编译?

2 个答案:

答案 0 :(得分:14)

虽然您没有直接定义start(),但通过扩展Thread,正在向def及其子类提供start()的实现,从而履行合同abc界面。

答案 1 :(得分:2)

您的完整班级已经从start()类继承Thread方法,该方法具有完全相同的签名。这就是编译器不会产生任何错误的原因。