我有一个类和一个接口:
public interface A {
public void getNum();
}
public class B {
public void getNum() {
System.out.println("4");
}
}
public class C extends B implements A {
protected void getNum() {
System.out.println("3");
}
}
Run Code Online (Sandbox Code Playgroud)
现在我的问题是,为什么这段代码会出现编译错误,我们怎样才能避免它.有没有办法在C类中覆盖这个方法?
public class Mayank {
public static void main(String ...aa){
System.out.println("Yes it is working");
}
}
Run Code Online (Sandbox Code Playgroud)
如果我们使用这种语法,程序的效率是否有任何降低.