Technically they do have names, but you cannot reference them. but your examples aren't anonymous classes
To use an anonymous class that implements an interface, you'd use the syntax:
InterfaceName obj = new InterfaceName(){
// methods here
}
Your examples are just using the interface as a reference type. In your second example, you will get a classcastexception if the class doesn't implement the interface. implementing the methods is insufficient.
This post was edited by carteblanche on Dec 4 2013 07:04am