Java Quick Reference
  Language Fundamentals
  Operators and Assignments
  Flow Control and Exceptions
  Declarations and Access Control
  Garbage Collection
  Overloading and Overriding
  Threads
  The java.lang Package
  The java.util Package
  The java.awt Package
  The java.io Package
  References
  Miscellaneous Notes
  Tips & Traps
  Mock Exams

Overloading, Overriding, Runtime Types and Object Orientation - Anonymous Classes

  • anonymous classes are classes which have no name
  • they are declared and defined using the name of the class or interface they extend ie new Enumeration()
  • no modifiers, extends or implements are allowed
  • if any parameters are passed the superclass must have a corresponding constructor
  • Anonymous classes do not have constructors of their own as constructors always take the name of the class and Anonymous classes have no name
  • even though you cannot use an extends clause, you can extend the superclass by overriding methods

    you cannot 'overload' or 'add' new methods. See example code

  • Once you create an anonymous class and override a method, that method is used until the class is unloaded
  • they are most often used to implement an event listener interface or extend an adapter class

Example Code

Encapsulation Polymorphism isA/hasA Overloading Overriding Field Variables
Initialization Top-level Classes Inner Classes Static Nested Classes Local Classes Anonymous Classes