Modifier Types
Access modifiers and non-access modifiers
Access Control Modifiers:
Visible to the package, the default. No modifiers are needed.
Visible to the class only (private).
Visible to the world (public).
Visible to the package and all subclasses (protected).
访问级别 access control modifier 同类 同包 子类 不同包
public public yes yes yes yes
protected protected yes yes yes
default yes yes
private private yes
Abstract modifier
An abstract class can not be instantiated. If a class is declared as abstract then the sole purpose is for the class to be extended. An abstract class may contain both abstract methods as well concrete methods. 抽象类可以没有抽象方法,但包含了抽象方法的类必须被定义为抽象类。
An abstract method has no implementation. The methods body(implementation) is provided by the subclass.
抽象类和抽象方法都不能被final修饰。
Final modifier
用final修饰的类不能被被继承,没有子类。 用final修饰的方法不能被子类的方法覆盖。 用final修饰的变量表示常量,只能被赋一次值。
A reference variable declared final can never be reassigned to refer to an different object. However the data within the object can be changed.
Static modifier
The static key word is used to create variables and methods that will exist independently of any instances created for the class. class variable , class method.
static method can not access instance variable or instance method.