As you might guess an anonymous class cannot have be given a constructor by the programmer. Think about it, a constructor is a method with no return value and the same name as the class. Duh! we are talking about classes without names. An anonymous class may extend another class or implement a single interface
A class defined within a method can only access fields in the enclosing method if they have been defined as final. This is because variables defined within methods normally are considered automatic, ie they only exist whilst the method is executing. Fields defined within a class created within a method may outlive the enclosing method.
Any ideas, resources,sample code,links, highly appreciated. thanks in advance.
posted 4 years ago
There are several errors in your quotes. A constructor isn't a method. The behaviour of local variables is described correctly, but we do not usually use the word automatic to describe such behaviour. The code you quote contains a compiler error.