Can a file hold two public classes? //file name test.java public class test {} public class test1 {} This gives a compilation error: "test.java:3: Public class test1 must be defined in a file called "test1.java". I remember reading a posting in javaranch that a file can contain 2 public classes.
class file for public class should be named same. eg: public class fun { } should be written in 'fun.java' and you can't have duplicate class names think you can't have public class joke { } inisde 'fun.java' it should be inside 'joke.java'