Java modifier range

Source: Internet
Author: User

Class:

In Java, class modifiers include private, default (package), protect, and public. Their scopes are as follows:

Range Private Default Protected Public
Same class √ √ √ √
Classes in the same package   √ √ √
Classes in the same package and subclasses in different packages     √ √
All       √

 

Supplement: there are also final, and abstract modifiers:

The final-modified class cannot be inherited and has no subclass.

Abstract-modified classes cannot be instantiated and must be inherited by the quilt class. As long as a class has an abstract method, it must be an abstract class, but the abstract class does not have to have an abstract method.

 

Variable:

1. There are no global variables in Java, as long as the method variables, instance variables (non-static variables in the class), class variables (static variables in the class)

2. the variables in the method cannot have access modifiers.

3. The class variable modifier private, default (package), protect, public and class range are the same. The following describes the other types of variables:

Modifier
Name Description Remarks
Static Static variables (also known as class variables and other variables called instance variables) Can be shared by all instances of the class. You do not need to create a class instance to access static variables.
Final Constant. The value can only be assigned once and cannot be changed. Do not use Const. Although it has the same meaning as the const keyword in C and C ++, it can be used together with static to avoid maintaining a copy for each instance of the class.
Transient Tells the compiler that this variable does not need to be permanently saved during class Object serialization. It is mainly because the amount of changes can be obtained through other variables, and it is used for performance problems.
Volatile It is pointed out that there may be multiple threads to modify this variable, and the compiler is required to optimize it to ensure that the modification of this variable can be correctly processed.  

 

Interface:

Public is generally used.

 

Part from:

Http://www.bokee.net/bloggermodule/blog_viewblog.do? Id = 110495

 

 

 

 

 

Method: The modifier of the method is similar to that of the variable.

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.