There is a way to do this using var (added in Java 10):
var
var frenchGreeting = new HelloWorld() { public void g2() { System.out.println("do this too.. ");} public void greet() { System.out.println("Salute "); } }; frenchGreeting.g2();