If you are asking when to use nested class, then answer is as per your requirement and design. You are free to use nested class, but sometimes it will make you hard to understand the design and changes to it, if it was not properly done.
I'm quoting Oracle Official Document
Compelling reasons for using nested classes include the following:
- It is a way of logically grouping classes that are only used in one place
- It increases encapsulation
- It can lead to more readable and maintainable code
As I mentioned, for me it doesn't make sense to have
audio as inner class, but again its upto your design/requirement, also I'm not sure why did you declared your main method inside inner class ?? So, I was suggesting you
public static void main (String args)
//lots of code
class ImageImp implements ImageObserver
//lots of code and other methods here so I'm going to leave it out
Then you should take out inner class
class audio extends Thread
public void run ()
Your design should be simple and should make some sense. Don't try to put everything inside one class until it is really needed.