Implement two interfaces in an anonymous class

后端 未结 4 1821
南方客
南方客 2021-02-06 21:08

I have two interfaces:

interface A {
    void foo();
}

interface B {
    void bar();
}

I am able to create anonymous instances of classes impl

4条回答
  •  南笙
    南笙 (楼主)
    2021-02-06 21:20

    "An anonymous inner class can extend one subclass or implement one interface. Unlike non-anonymous classes (inner or otherwise), an anonymous inner class cannot do both. In other words, it cannot both extend a class and implement an interface, nor can it implement more than one interface. " (http://scjp.wikidot.com/nested-classes)

提交回复
热议问题