An anonymous inner class is one that is created AND defined within the body of another class's method. In essence, you are creating a concrete class on the fly from an abstract definition. What you have so far with your InnerClass class is actually just a regular inner class, meaning non-anonymous.
If you want to experiment with anonymous inner classes, the simplest way I can think of is to change your InnerClass to an interface, like so:
public interface InnerClass{
public void doSomething();
}
So at the moment, InnerClass does squat; it has no meaning until it is defined. Next, you'll want to change how OuterClass works. Change your showThis() function like so:
public showThis(InnerClass innerObj){
innerObj.doSomething();
}
Now we have your outer class asking the inner class instance to do something, but we still have not defined what it is we want it to do. This is where the magic happens - in your main method, you will define what the inner class instance actually looks like:
public static void main (String[] args){
OuterClass outer = new OuterClass();
// This is the key part: Here you are creating a new instance of inner class
// AND defining its body. If you are using Eclipse, and only write the
// new InnerClass() part, you'll notice that the IDE complains that you need
// to implement the doSomething() method, which you will do as though you
// were creating a plain 'ol class definition
outer.showThis(new InnerClass(){
public void doSomething(){
System.out.println("This is the inner anonymous class speaking!");
}
});
}
In practice, I've not used anonymous inner classes too much, however they are useful to know about. I have used them most often when I am doing GUI programming, to define listeners for GUI control events, such as a button click.
Also, as other people have mentioned, keep in mind that the Java standard has the first letter of the class name a capital letter, which I have done here. You'll want to follow that standard as it makes it far easier for other people to read your code, and at a glance you can very easily tell when you're looking at a class, and when you're looking at an object.
Anyways, hope that helps.