This question already has an answer here:
Animal is a user defined class here.
Animal D = new Animal("Leo") { @Override public void makeNoise() { System.out.println("Roar!"); } }; D.makeNoise();
This question already has an answer here:
Animal is a user defined class here.
Animal D = new Animal("Leo") { @Override public void makeNoise() { System.out.println("Roar!"); } }; D.makeNoise();
Its called an anonymous class and used to define the class and any overridden methods at the same time.
That is an anonymous class. For details about anonymous classes and why they are useful, see this tutorial on anonymous classes.
This is used to override the initial
Animal.makeNoise()
method with a custom one for just this instance.