They are called "Anonymous Inner Classes". They are basically an implementation of an interface/abstract class without having to write a fully blown class.
The compiler will actually create a class for each one of these, so if you compile the above code, you'll see something like:
Main.class
Main$Visitor.class
Main$1.class <-- This is probably the "adder" implementation
Main$2.class <-- This is probably the "multiplier" implementation
The beauty of these classes is that they can read stuff from your method/class without you having to pass those parameters. For instance:
...
final int extraMultiplyer = 10;
Visitor multiplier = new Visitor(){
public int DoJob(int a, int b) {
//Note that extraMultiplyer is defined in the main() method
//and is final.
return a*b*extraMultiplyer;
}
};
...
They are particularly useful for event handling (think Swing), where you usually need to implement the ActionListener interface where you need to have a actionPerormed() method.
If you have a UI class with many different controls, whenever you register the listeners, you might want to register these annonymous classes to: a) make the code (arguably) more readable and b) to make it easier to know what each component does, instead of having a giant "if-else if-else" style actionPerfomed implementation
for instance:
//abbreviated code
button1.addActionListener(new ActionListener(){
//you do what you need here for the action of pressing this button
});
button2.addActionListener(new ActionListener() {
//you do what you need here for the action of pressing this button
});