Four types of access modifiers in Java: Public, Protected, default (no modifiers, defaults), private.
Four modifiers that can be modified (class, method, member variable)
Public
Protected
Default
Private
3 minutes to figure out the three major modifiers of JavaJava three decorations: Static,final,abstract, in the Java language everywhere, but they can modify what components, the meaning of the cosmetic component and what limitations, always confused. So to summarize the comparison.1 static modifierThe static modifier is capable of decorating the property, method, and initial code block. Local variables and
reference:http://www.studytonight.com/java/modifier-in-java.phpModifiers is keywords that is added to the change meaning of a definition. In Java, Modfiers is cateogrized into and types:1. Access Control modifier2. Non Access modifier1) Access control modifierJava language have four access modifier to control access levels for classes, variable methods and constructor.
Default: Default have scope o
The Java language defines the 6 common modifiers of public, protected, private, abstract, static, and final, as well as 5 less commonly used modifiers, and below is an introduction to the 11 Java modifiers:
1.public
Working with objects: classes, interfaces, members
Descr
is not a keyword in java.)Private: personal, Internal access, well understoodPublic: shared, accessible, Better understoodPackage (friendly: can be accessed with a single packet)Protected: the same package or subclass can be accessed
class modifier
Public
can be accessed from other classes
Abstract
This class
Available modifiers for classes, methods, member variables, and local variables
Modifier
Class
Member Methods
Construction method
Member variables
Local variables
Abstract
Y
Y
_
_
_
Static
_
Y
_
Y
_
Public
Y
Y
Y
Y
_
Protected
_
Y
problemJava modifier: public,protected,private, without modifiers. What difference does it have?Essence AnswerAs shown in the following table, y means access (visibility), n means no access, for example, 3rd y of the first row, the variable/method of the class is accessible to the variable/method if it is decorated with public.
Modifier
Class
1. Modifier A in Java. Permission modifiersPrivate, default, Protected,publicB. Status modifierStatic,finalC. Abstract modifiersAbstract2. Class modifiersPublic (access control), declare a class as a common class, he can be accessed by any object, the main class of a program
Access Control modifiersIn Java, you can use access controls to protect access to classes, variables, methods, and construction methods. JAVAV supports 4 different types of access rights.
default (That is, by default, nothing is written): it is visible within the same package, and no modifiers are used. Use objects: classes, interfaces, variables, methods.
Private : Visible within the same clas
)
Objective:transforms the interface of one class into another interface that the customer Wants. a D a P T e r mode makes it possible for those classes that would otherwise not work together because of incompatible interfaces to work Together. Principle:Target Interface ( Target): The interface that the customer Expects. a class that needs to be adapted ( Adaptee): A
Available modifiers for classes, methods, member variables, and local variables
Modifiers
Class
Member Methods
Construction method
Member variable
Local variables
Abstract
Y
Y
_
_
_
Static
_
Y
_
Y
_
Public
Y
Y
Y
Y
_
Protect
2017-11-04 21:51:04Class:
By default, public (A. java file can have only one public class), Final,abstract
own definition, public mostly
Do not allow the use of static,private,protected
Member variables:
Four permission modifiers are available, final,static
own definition, private majority
Do not allow the use of abstract
Construction
decorated, the Java Virtual Machine (JVM) skips that particular variable .The modifier is included in the statement that defines the variable, which is used to preprocess the data type of the class and variable. volatileOlatile-Modified member variables force the value of the member variable to be re-read from shared memory each time it is accessed by the thread. Also, when a member variable changes, the t
changed, it will cause great confusion, so the Java compiler requires that all local variables accessed by the inner class must be decorated with the final modifier.
Finally, this paper deeply analyzes the function of final modifier in Java, it seems that the simple behind, in fact, contains a lot of important truth. Learning a technology is not limit
given an initial value and cannot be modified
Method Modifiers
Public
It can be accessed from all classes
Protected
It can only be accessed from this class and its subclasses
Private
It can only be accessed from this class
Abstract
No method body, belongs to an abstract
permission size for four rights modifiers (public, protected, default, private)
Note: Default, does not have this keyword, it thinks that defaults, that is, nothing added!Generally, the default visibility is package visibility (package visibility).
This class
under the same package (subclasses and unrelated classes)
under different packages (subclasses)
under different packages
package
C: If there is no package, the default is the No bag name
(5) Compile and run with package
A: Manual Type
B: Auto-type
"Javac–d. Helloworld.java "
3. Guide Package
(1) Every time we use a class with a package, very troublesome, this time provides a keyword
(2) Format:
A:import Package Name: class n
console does not work.
The role of the jar file:
1. Easy for users to run a project quickly.2. Provide tool classes to others in the form of a jar package.
If you use a class inside a jar package, you must first set the Classpath path.JRE = jvm+ Core Class Librarypackage qq;import javax.swing.*;class Demo9 { publicstaticvoidmain(String[] ar
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.