找了几道改错题练练,越练越没信心了,基础啊。。。伤不起啊- abstract class A
- {
- public abstract void fun();
- interface B
- {
- public void fun();
- }
- }
- class X extends A
- {
- public void fun()
- {
- System.out.println("class X..........void fun()");
- }
- class Y implements B
- {
- public void fun()
- {
- System.out.println("class Y........void fun()");
- }
- }
- }
- class Test
- {
- public static void main(String[] args)
- {
- A a=new X();
- a.fun();
- //A.B b=a.new Y();
- A.B b=new X().new Y();
- b.fun();
- }
- }
复制代码 A a=new X();
a.fun();
//A.B b=a.new Y(); //a相当于 A a=new X(); 抽象类不能实例化 或者把A a=new X() 改成X a=new X(),或者把a改成new X()
A.B b=new X().new Y();
b.fun();
刚查了,抽象类里是可以包含接口的,反之接口里也可以包含抽象类的,我改了一下,感兴趣的看一下,呵呵- interface A
- {
- public void fun();
- abstract class B
- {
- public abstract void fun();
- }
- }
- class X implements A
- {
- public void fun()
- {
- System.out.println("class X..........void fun()");
- }
- class Y extends B
- {
- public void fun()
- {
- System.out.println("class Y........void fun()");
- }
- }
- }
- class Test2
- {
- public static void main(String[] args)
- {
- A a=new X();
- a.fun();
- //A.B b=a.new Y();
- A.B b=new X().new Y();
- b.fun();
- }
- }
复制代码 实例化跟上面都一样了,不论接口还是抽象类都必须子类去实例化
|