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.

2 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
  2. Really appreciated the information and please keep sharing, I would like to share some information regarding online training.Maxmunus Solutions is providing the best quality of this JBOSS Technology And this online training will be very convenient for the learner.And the training will be online and very convenient for the learner.

    For Joining online training batches please feel free to call or email us.
    Email : minati@maxmunus.com
    Contact No.-+91-9066638196/91-9738075708
    website:-http://www.maxmunus.com/page/JBoss-Administration-Training

    ReplyDelete