Modifiers for Java

Source: Internet
Author: User

Class modifier:

Public (access control character), declare a class as a common class, he can be accessed by any object, the main class of a program must be a public class

Abstract, declaring a class as an abstract class, without implementing a method, requires a subclass to provide a method implementation

Final, declaring a class as final (that is, non-inheriting), indicating that he cannot be inherited by another class

Member Variable modifiers:

Public access control, which specifies that the variable is public and that he can be accessed by any method of the object

Private access control, which specifies that the variable allows access only to methods of its own class, and that methods in any other class (including subclasses) are inaccessible

Protected (Protected access control) specifies that the variable can be accessed by its own classes and subclasses. This variable can be overridden in a subclass

Final final modifier, specifying that the value of this variable cannot be changed

Static modifier Specifies that the variable is shared by all objects, that is, all instances can use the variable. Variables belong to this class

volatile (volatile modifier) specifies that the variable can be controlled and modified by several threads at the same time

Method Modifiers:

Public (common control character)

Private (proprietary control) specifies that this method can only be accessed by methods such as its own class, which cannot be accessed by other classes (including subclasses)

Protected (Protected access control) specifies that the method can be accessed by its classes and subclasses

Final, specifies that the method cannot be overloaded

Static, specifying a method that can be activated without instantiation

Synchronize, synchronous modifier, which is used in multiple threads to lock the method to which he belongs before running, to prevent access to other threads, and to unlock after the run is finished

Native, local modifier. The method body that specifies this method is written outside of the program in another language

Modifiers for Java

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.