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.