Java Beginner Knowledge points

Source: Internet
Author: User

System.out.println (); Print the text inside to change-line.

System.out.print (); No Line break printing

Error reason analysis:

The compiler prompts class A to be public and should declare an error in a file named A.java.

First Kind

"Class A is public and should be declared in a file named A.java" This sentence needs to be understood in two steps:
1. If Class A is declared public, then class A must be stored in a file named A.java, and the class name should be the same as the file name;
2, conversely, a file contains a maximum of a top-level public class, and the public class name is the same as the file name. For example, in file A.java, one or more classes are allowed to be defined, but at most a top-level public class is allowed, and this class is named A. The top-level emphasis here means allowing non-top-level public classes to exist, such as internal public classes.

The second Kind
This is your naming error. Change the file name to A.java because the class inside you is public class a{} either you get rid of your common (pubic) or you want to keep the class name consistent
Third Kind
There can be at most one class in a file that is public, so you can expose the definition of a class to be accessible to other classes! If you already have this common class, then this file name must be the same as the class name!
Also note that if you have only built a Java file, public can only declare before public static void main, or even if the class name of the public you have defined is the same as the name of the Java file you declared, it can only be in vain.



Java Beginner Knowledge points

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.