Sunday, November 30, 2008



We get error message "class [ClassName] is public, should be declared in a file named [ClassName].java" if the file name of the Java source program is not same as the public class name.

Solution is to rename the file or the class name to make them same. If a public class name is ABC then the file name of that class must be ABC.java. So always copy the class name and paste it when naming the file, then we will not face this error anymore.

If the above solutions do not work for you. Please comment below giving your code. I'll try to respond.

1 comments:

  1. not necessarily. remember, you can have several classes in one file.
    to complete your previous post:
    the name of the file must be identical to the name of the public class name. it is very well possible to have a

    Loader.java file without a Loader - class in it, even though it can contain several other classes.

    ReplyDelete