Reputation: 860
What it called when you have a class body after you create an object and what it's useful for?
Example:
public MyObject myObject = new MyObject() /*from here*/{
void myMethod() {
//code
}
};/*to here*/
Because usually it just looks like this:
public MyObject myObject = new MyObject();
Upvotes: 1
Views: 66
Reputation: 11028
They are called Anonymous Classes. Check out the docs: https://docs.oracle.com/javase/tutorial/java/javaOO/anonymousclasses.html
It's a way to derive from a class in just the place that you want to use it.
Upvotes: 5