Are anonymous classes a subset of inner class?

后端 未结 2 1065
小蘑菇
小蘑菇 2021-01-29 07:45

It might sound like a dumb question, but all anonymous classes must be defined and instantiated within an existing class; therefore, they must be inner classes at the same time.

2条回答
  •  旧时难觅i
    2021-01-29 08:26

    Anonymous classes are types of inner classes. See http://docs.oracle.com/javase/tutorial/java/javaOO/innerclasses.html

    Quoting from there:

    "You can also declare an inner class within the body of a method without naming the class. These classes are known as anonymous classes."

提交回复
热议问题