javaclass

Why does java compiler generates multiple .class files for single java File?


Why does java compiler generates multiple .class files for single Java File?

I have written some Java code Deadlock.java, on compiling this it generated multiple classes Named Deadlock$someNumber.class.

Why does this happen?

What is the significance of it?


Solution

  • I beleive it usually does that when you use anonymous inner classes. Each of those classes will get a class file but as you declared no name for them , it gets a number. So any unnamed class declaration you created (perhaps for Runnable or Listeners etc) is probably creating those.