Normal Java Class vs Anonymous Inner Class

  • A Normal Class can extend only one Class at a time & Alsoana Anonymous Class can extend only one Class at a time.
  • A normal Java class can implement any number of interfaces at a time, but an anonymous inner class can implement only one.
  • A normal Java class can extend a class and can implement any number of interfaces at a time (simultaneously) but the anonymous inner class can not extend a class and implement an interface at a time.
  • In a normal Java class, we can create any number of constructors but in an anonymous inner class, we can not create any constructor explicitly because the name of the constructor and the name of the class must be the same but the anonymous inner class does not have any name.

Note –

If the requirement is standard and required several times then we should use a normal top-level class.

If the requirement is temporary and required only one then we should go for anonymous inner classes.

Similar Java Tutorials

Leave a Comment