About those modifiers in the Java language

Source: Internet
Author: User
Tags modifiers

A. Some modifiers are provided in Java that can be used to decorate classes, variables, and methods, and in Java common modifiers are: abstract (abstract), static (static), public (common), protected (protected), Private ( private), synchronized (synchronous), native (local), transient (ephemeral), volatile (volatile), final (immutable)

Two. Modifiers that decorate the top-level class include abstract, public, and final, while static, protected, and private cannot decorate the top-level class. Member methods and member variables can have multiple modifiers, while local variables are only final decorated

Three. Accessible range of 4 access levels

Note: The top-level class can be modified only by default modifiers and public, not by private and protected

Four. The abstract modifier can be used to decorate classes and Member methods

1. Abstract classes that are represented by a class with an abstract class cannot be instantiated

2. Abstract methods are represented by an abstract method, and there is no method body: "{}" forsubclasses overriding

3.abstract decorated classes, that is, abstract classes can have common methods and abstract methods

4. Abstract classes and abstract methods cannot be decorated with the final modifier. the abstract modifier cannot be associated with the final modifier

Five. Final modifier

1.final is "immutable" meaning that it can modify non-abstract classes, non-abstract member methods, and variables

2. A class with a final decoration cannot be inherited, no subclasses

3. The method of final modification cannot overwrite the methods of the quilt class

4. A final modified variable represents a constant, such as (PI), so it can only be assigned once and cannot be changed

Six. Static modifier

1. Static variables are represented using static modified member variables, which can be accessed directly by the class name

2. Static methods are represented with static modified member methods, which can be accessed directly through the class name

3. A code block is sent with a static modified program, when the Java Virtual Machine (JVM) is full: Java Vsan can locate them within the method of the runtime data area based on the class name, and can only run once

About those modifiers in the Java language

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.