Filename for a public Class

A public class must be placed in a file that has a filename of the form ClassName.java, so class Welcome1 is stored in the file Welcome1.java.

Image Common Programming Error 2.2

A compilation error occurs if a public class’s filename is not exactly same name as the class (in terms of both spelling and capitalization) followed by the .java extension.

Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.