Alibabacloud.com offers a wide variety of articles about java class access modifiers, easily find your java class access modifiers information here online.
(self):PrintC.__nameclassD (C):defShow (self):PrintC.__nameC.__name #class Access ==> errorobj=C () obj.func ()#The ==> within the class can access the correctObj_son=D () obj_son.show ()#==> errors can be accessed in derived classesNormal field
Public common fields: objects can be accessed, accessible
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
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
Java learning notes 8 --- class static variables and static methods access and call methods, java learning notes
Static variables are also called class variables, static methods are also called class methods. They are collectively
();ArrayList list2 = new ArrayList ();}}1.4 Permission ModifiersThere are four access rights in Java, and when different access rights are used, the modified content has different access rights, and the following table describes the ability to access different permissions:
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
Java has four access rights, three of which have access modifiers, private,public and protected, and one without any modifiers.
The narrowest modifier for access restrictions in the Private:java language is generally refe
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
cycle of an object is determined by the braces {} defined by the object. Each time a program executes a flow into a statement block, the object of the statement block's automatic lifecycle will be created and initialized at the same time.
Iii. Storage Class Modifiers(1) AutoThe auto modifier can only be used for object declaration in the function. Objects with auto mod
Definition of Class
Modifier
Meaning
1
None or internal
Classes can only be accessed in the current project and cannot be accessed after other projects are referenced
2
Public
can access the class anywhere
3
Abstract
cannot be instantiated, only for inheritance
Questions for class member modifiers
Class a{ private static $p 1; public static $p 2;}
As in the code above, the member variable is preceded by the private static modifier and only with the private difference where? Similarly, where is the difference between public static and public?
------Solution--------------------
Static keyword: Declaring a
();Attention:1 "override method name, return value, parameter Table. Modifiers are the same as, or more broadly than, the parent class2 "static methods can only be overridden by static methods, and there is no polymorphism,What type is a reference type and what type of method is called?3. Initialize the code blockStatic initialization of code baseFunction: Assigning a value to a static propertyClass is executed once at load time, only onceClass Loadi
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
modifier typemodifierDescriptionaccess Control modifiersdefaultDefault (that is, default, nothing): It is visible within the same package , without any modifiers. Use objects: classes, interfaces, variables, methods. Private Private : visible within the same class. working with objects: variables, methods. Note: Classes cannot be decorated (external classes) PublicPublic : visible to all
comment/* Comment content * * Note: The content of the comment will not be compiled, just explain the description block comment/**..........*/Document comment change (values that can be changed) and constants (values that cannot be changed); Array of operator statements binary, decimal, hexadecimal; conversion between binary ()Eight basic data TypesNumeric: Integer: Byte, short, int (most commonly used), long (for larger data); Floating point (decimal): Float (single precision-) write the data
common modifiers used by classes and their components in Java(1) Classification of modifiers: Permission modifiers:private, default, protected, public status modifiers:static, Final abstraction modifier: Abstract(2) modifiers used for common classes and their composition: of the Modified
.
If a class is final, all methods in the class are final.
Expansion and Promotion:
Static,final and abstract are not able to modify the construction method
Class loading
Concept: When the JVM uses a class for the 1th time, it first finds the corresponding.
modifying a method, this method is loaded with the load of the class and is invoked directly by the class name. The methods in many tool classes are static and are invoked directly through the class name. Method Name. Non-static member variables and Non-static methods cannot be used in static methods.
Static code block
A static code block (a
The member variables of a Java class typically have the following access modifiers:
Public, private, protected, or default,
For example, in package first, if there is a class FirstClass with four variables:
public int pp;
private int Xiaopp;
protected int DD;
int xiaod
static properties;Final -The ultimate1, modifier class-The final class, the class cannot be inherited (the purpose is that the class can not be extended, that is, cannot be changed);2, the modification method-the final method, the method can not be overridden by the quilt class
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.