I have 2 classes in a single Java source file, and the name of the source file is the same as the public class. When I run the source file, I get the following error:
package inheritance;
class clsnae {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("first");
}
}
public class clsname {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("second");
}
}
- May I know why my compiler or JRE can't find my other file (non-public file)?
- If I remove the
publickeyword, it just prints "first" and not "second", but after adding thepublickeyword to the class name, why does it still try to run the first class instead of running the second class?




