You created an anonymous subclass of Object , which introduces a method called hi , after which you call this method with the "strange" parameter.
Suppose you had:
class NamedClass extends Object { void hi(String in) { System.out.println(in); } } NamedClass instance = new NamedClass(); instance.hi("strange");
If this class was needed exactly in one place, there is no real need to be named, etc. - making it an anonymous class, you will get rid of its name, the class will be defined and instantiated, and the hi method will be called immediately within the same expression.
source share