Java访问权限 & 关键字

public/private/protected...

Posted by freeCookie🍪 on January 6, 2017

Java成员访问权限 & 关键字

突然发现不是很明白它们的区别和含义😱

Access Specifiers 访问权限修饰符

Access Specifiers

中文参考

  Class 类内 Package 包内 Subclass 子类 Others 外部
public Y Y Y Y
protected Y Y Y N
default Y Y N N
private Y N N N

Keyword 类成员变化修饰符

Java keywords list

一个中文

Java 多线程

Volatile关键字解析

  Class Method Variables
static Only nested classes can be static. Belongs to the class (not object), can be invoked without the need for creating an instance of a class, can access static data member and can change the value of it. Can be used to refer the common property of all objects, gets memory only once in class area.
final Cannot be subclassed (inherited). Cannot be overridden or hidden by subclasses. Can only be initialized once.
abstract Abstract classes cannot be instantiated, but they can be subclassed. A method that is declared without an implementation. If a class includes abstract methods, then the class itself must be declared abstract. (._.)
synchronized Only one thread may enter the block. If an object is visible to more than one thread, all reads or writes to that object’s variables are done through synchronized methods. Intrinsic Locks and Synchronization
volatile ╮(╯▽╰)╭ volatile Every thread accessing a volatile field will read its current value before continuing.