0

I went ot go look at my class folder today to submit a project when I stumbled across duplicate classes. For example my class would be called MainPro.class and there would be duplicates such as MainPro$1.class, MainPro$2.class etc.

It's for a GUI project that uses java.swing

I'm unsure of what these are and am too afraid to delete it incase it ruins my coursework.

Thanks.

Kelo
  • 1,783
  • 2
  • 9
  • 21

1 Answers1

2

They're the class files for anonymous classes. For example, if you write

  Foo = new Foo() {
       ....
  }

then that's defining a class that extends class Foo but which has no name. The compiler will create a class file based on the name of the file that definition appears in, plus a dollar sign and a number.

There may be other reasons for "MainFile$N" classes as well, but this is one example.

They're created when you compile the Java source. They're needed to execute the program, but like any .class they will be regenerated on the next compilation of the file that defines them (in your case MainPro.java)