Java learning-differences between public, private, protected, and other modifiers, privateprotected
Public, private, protecte, and default are used to define the access permissions of members in Java, that is, no permission modifier is added before the Members. For example:Public class {Void method (){};}Method is the default permission.
The access permissions o
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 class: There a
I. Some of the modifiers provided in Java that can modify classes, variables, and methods, which are common in Java: abstract (abstract), static (static), public (common), protected (protected), Private ( private), synchronized (synchronous), native (local), transient (temporary), volatile (volatile), final (immutable)
Two. modifier top-level class
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 cannot be instantiated
Final
Subclass can no longer be declared
In the Java programming language, modifiers are modifiers that appear in the definition of a class, properties, methods, constructors, initialization blocks, and so on. Modifiers are divided into the access modifier and optional modifiers, they are basically keywords, there
An understanding of possessive number modifiers in Java regular expressions the regular expression for the number qualifier such as, +, *, {n, m} matches by default is greedy mode, for example: a.*b match acbab result is acbab instead of ACB regular expression support lazy mode, That is, add a number modifier (quantifier) to the number qualifier, with a question
Reprint: http://wuhaidong.iteye.com/blog/851754There are 4 types of access modifiers in the Java languageThere are 4 access modifiers in the Java language: package (default), private, public, and protected.1. The package is the default protected mode, plus a packet access, which is used when there are no
anonymous inner class or a normal inner class. Otherwise, an error is compiled. Why must it be declared as a final type? This is because for ordinary variables, its scope is to stay within the method, when the method execution ends, the local variable disappears, but the inner class may produce an implicit "closure", the closure of the local variable out of the way it continues to exist. Look at the following example:
Public classClosuretest { Pu
abstract class. Abstract classes can contain no abstract methods.Other modifiersSynchronized modifierThe method of synchronized keyword declaration can only be accessed by one thread at a time. The synchronized modifier can be applied to four access modifiers.transient modifierWhen a serialized object contains an instance variable that is transient decorated, the Java Virtual Machine (JVM) skips that particular variable.volatile modifierA volatile-mo
In Java classes, we often see static keywords, which are often referred to as statics. The static modifier can be used to decorate a data member, a method member, but not a class (this refers to an external class) and cannot modify a construction method. For example,
package com.csst.vo; public class User { private String name; private static int count; Public String getName () { return name; }
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 xiaodd;
If there is another class in package-Secondclass inherits FirstClass:
Then he will in
Java modifier type (public,protected,private,friendly)Public classes, generic variables and methods, and any class within and outside the package can be accessed;Protected classes, generic variables and methods, any class within the package, and those outside the package that inherit from this class can be accessed;Private class, generic variables and methods, any class outside the package can not be accessed;If a class, a generic variable, and a meth
The difference between 4 modifiers in Java and the whole process of explanationHttp://jingyan.baidu.com/article/fedf0737700b3335ac8977ca.htmlThe modifiers in Java 4 are public, protect, default, private, which explains the object-oriented encapsulation, so we want to apply them as much as possible to minimize the permi
abstract and final decorated . If a class contains an abstract method, the class must be declared as an abstract class, or a compilation error will occur.Abstract classes can contain both abstract and non-abstract methods. abstract MethodsAn abstract method is a method that does not have any implementation, and the specific implementation of the method is provided by the subclass.Abstract methods cannot be declared final and static.any child class that inherits an abstract class must implement
accesses it, it is the same copy.Instance methods and instance variables cannot be accessed directly in a static method.The This and Super keywords cannot be used in static methods.Static methods cannot be modified by an abstract.Static member variables can be accessed using either the class name or the object, and non-static member variables can only be accessed using the object.Static functions can access static members directly, but they cannot access non-static members directly., non-static
Java modifiers can be divided into two types
Accessible modifiers
Non-accessible modifiers
Using modifiers, you can use the definition of the class, method, variableAccessible modifiers
Package visible,
Tag: code specifies default visibility. SH Engineer Strong Object StatOne, Java access modifierAccess modifiers to control the visibility of members in a classThere are four access modifiers, respectively: default,private,public,protected1, default: No write modifiers are required by default. can only be accessed withi
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 Method:
Four permission
Java has four access rights, three of which have access modifiers, private,public and protected, and one without any modifiers. Where the package represents the default access rights, the code is the default case where no modifiers are written. For the sake of good, name the package for the moment. PublicprotectedPriv
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),
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.