抽象类跟接口声明的引用,不能调用接口或抽象类中没有定义的方法
抽象类和接口声明的引用,不能调用接口或抽象类中没有定义的方法
package arrays; public class AList extends ListInterface{ public boolean isFull() { System.out.println("isFull method "); return false; } public void istrue() { System.out.println("istrue method "); } public void isFalse(){ System.out.println("isflase method"); } public static void main(String[] args) { ListInterface lis = new AList(); // 抽象类和接口声明的引用, 都不能调用 接口或抽象类中没有定义的方法 //lis.isFolse(); 会报错 } }
接口或抽象类中声明了两个方法 isFull 和 isTrue , 子类新添了一个方法 isFalse 。 用接口声明实例化子类的时候, 不能调用父类或接口中没有定义,而子类新添的方法 . 这是为什么涅, 在 jvm中的实现是怎么样的捏? ?
package arrays; public abstract class ListInterface { boolean isFull() { return false; } abstract void istrue(); }
属性能够抽象到接口中吗? 因为接口是 public 的 。使用抽象类可以私有化属性让子类继承。