Multiple choice technology programming languages

Is it allowed to define a constructor for anonymous class?

  1. Yes

  2. No

  3. In specific conditions

  4. Not sure

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Java anonymous classes do not have a name, which prevents developers from declaring constructors, since a constructor must share the name of its declaring class. Instead, custom initialization is achieved using instance initializers or by passing parameters to the superclass constructor, so defining a constructor is not allowed.