Basic syntax format in Java 2

Source: Internet
Author: User

Static modifiers

Static modifiers, which are generally decorated members. Members that are modified by static belong to a class and do not belong to an object of a single class.

Members that are modified by static can and recommend direct access through the class name.

Static code block

Definition: is a block of code that is defined at the member location, using static adornments.

Characteristics:

It takes precedence over the execution of the Main method, which takes precedence over the construction of code block execution, when used in any form for the first time to the class.

The static code block executes only once, regardless of how many objects are created.

Can be used to assign a value to a static variable for class initialization

Final keyword

The final decorated class cannot be inherited, but other classes can be inherited.

The final modified method can be inherited and cannot be overridden, but there is no final decorated method in the parent class, and the subclass can be overridden with a final decoration.

Final modifier local variable: One assignment at a time, a lifetime constant, a variable value of a reference type is an object address value, an address value cannot be changed, but an object property value within an address can be modified

  

Four types of access modifiers

To be accessible only in this class, use the private modifier;

The classes in this package can be accessed without modifiers (default);

To make the class in this package accessible to subclasses in other packages using the protected adornment

All of the classes in this project can be accessed using the public adornment.

Note: If the class is decorated with public, the class name must be the same as the file name. There can be only one public-decorated class in a file.

Basic syntax format in Java 2

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.