excuse me for asking such a generic question, but I can't phrase it better. I have seen code of this style fairly often, but have not yet used it.
variable= someClass.someMethod(new someOtherClass(){
methodDeclaration(){
}
});
If you don't know what I mean, the top answer could serve as an example: How do I check if the user is pressing a key?
When is this used? Are there any examples of problems that can only be solved by such code?