is there a way to declare 2 classes on the same .java file using Eclipse
Yes, you can have several classes defined in a single .java file, but there may at most one public class in each file. (Just as in your example.)
Note that if you have a public class in a .java file, the name of that class must be the same as the name of the .java file.
how the compiler will distinguish the .class for each declare class.
The names of the .class files does not depend on the name of the .java file, but on the identifiers of the class declarations.
If you have
class A {}
class B {}
in a file named Classes.java
, you'll get A.class
and B.class
if you compile it.