Why there is only one public class in a Java source File.

Source: Internet
Author: User

We've all come across a single source file that has multiple Java classes, but when the first class uses the public modifier, the following class uses the public modifier to make an Error. This means that a Java source file can have at most one public class.

When there is a public class, the source file name must be identical, otherwise it cannot be compiled, and if there is no public class in the source file, there is no consistency requirement in the file name and class.

The Java Virtual machine instance runs a Java program by calling main () of a class, and this main () must be public static void and receive an array of strings as a parameter, and any class that has such a main () can be the starting point for the Java Program. This main method must be in the class declared by Public. Public is used to differentiate the main class in the source file, and if there are multiple, the Java virtual Opportunity cannot find the program Entry.

Why there is only one public class in a Java source File.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.