In java can inner classes inherit from an abstract class defined outside of the inner class's outer class?
In java can inner classes inherit from an abs开发者_运维技巧tract class defined outside of the inner class's outer class?
Also can abstract classes implement constructors?
Yes to both.
For example it is quite common to extend Swing Listener Adapter classes in inner classes
Why didn't you just try it?
Do you mean...
abstract public class Outer {
public Outer() { System.out.println("Outer.ctor"); }
abstract public String foo();
}
public class Inner {
public static class Inner2 extends Outer {
public Inner2() { super(); }
public String foo() { return "Inner2.foo";}
}
public static void main(String[] args) {
System.out.println("main: " + new Inner2().foo());
}
}
...?
$ javac -d . Outer.java Inner.java
$ java -cp . Inner
Outer.ctor
main: Inner2.foo
(The superfluous calls to "super()" are merely illustrative, & are not necessary.)
精彩评论