Local classes are similar to inner classes because they cannot define or declare any static members . Local classes in static methods, such as the class PhoneNumber , which is defined in the static method validatePhoneNumber , can only refer to static members of the enclosing class.
Read moreWhat are local classes good for?
Local class: Use it if you need to create more than one instance of a class, access its constructor, or introduce a new, named type (because, for example, you need to invoke additional methods later). Anonymous class: Use it if you need to declare fields or additional methods.
Read moreWhat is local class in Java?
A local class is declared locally within a block of Java code, rather than as a member of a class . Typically, a local class is defined within a method, but it can also be defined within a static initializer or instance initializer of a class.
Read more