Java Some keywords: static, final, and abstract, interface, and access modifier Description

1, keywords can be modified instructions:

Keyword Property (whether modified) Method (whether modified) Class (whether modified)
static Yes Yes Yes
final Yes Yes Yes
abstract no Yes Yes

2, keyword meaning:

Keyword significance Specific properties Description Inherited, then what will happen?
static Represent the class. 1. Modified variables: belonging to the class
2. The modification methods: subclasses can override as static, but not cover the non-static.
3. Modified class: belongs to the class
See the following detailed instructions supplement
final That once the assignment can not be changed. 1. Modified Variable: Once the assignment can not be changed;
2. modification methods: subclass which can not be overridden;
3. modifications categories: it can not be inherited;
There will be no question of succession, because it represents immutable.
abstract Abstract, it represents just defined. 1. Modified Variable: No.
2. modified Method: abstract method is not implemented, and can only be inherited by subclasses implement
3. Modified classes: abstract class object instance is not generated, and only inherited by subclasses instantiable subclass. .
In order to inherit fully born.
interface abstract special case Prior to 1.8:
- public static final variable is the default type;
- The default method is public abstract type;
after 1.8:
- Method: define one or more static (static) method (it is a static method, but the definition has changed)
- methods: available default modifier is defined (it is a common method, but the definition has changed)
? Follow-up supplement

note:

Note: You can not put together modifiers: final, private, static, because abstract methods must be modified to achieve (coverage) in a subclass in order to invoke the multi-state, while more than modifiers in a subclass method of modifying the period covered this method is not.
final is not covered, private can not be inherited by subclasses will not cover, static although can be covered, but will call compile-time type of method is invoked, because the method is called the parent class, and parent class and abstract way, not be able to call, so the modifier can not be put together.

3, static inheritance and coverage explanation:

Note: The following is just a test, it is not recommended to visit the actual static variables through an instance object. Will be prompted to compile is not recommended, but the actual executable.

After the inheritance: the parent class A, class B sub Parent (class A) Properties (na) (static) Parent (class A) Method (static)
Promoter (type B) to cover (static) A.na / a.na represents: the parent class variables;
B.na / b.na showing: Variable subclass;
As shown below
Promoter (type B) to cover (non-static) A.na / a.na said: parent class variable;
B.na: Compile error;
b.na:B in ordinary member variables
As shown below
Promoter (Class B) does not cover A.na / a.na / B.na / b.na represent the same variable

The above does not consider another case: the case subclass object assigned to the parent class object. In this case: The output or contents of the parent class (true methods and variables).

The method of covering the test below:

4,4 kinds of access modifiers: public, protected, default, private

5, reference:

  1. Static variables of the same name after the succession problem analysis in Java - to be a happy man - CSDN blog
  2. Four Java access modifier public / protected / default (friendly) / private - mingjie1212's blog - CSDN blog
  3. Java foundation - final, static and abstract difference and use - insufficient funds - CSDN blog
  4. Java 8 特性 ——interface 中的 static 方法和 default 方法 - 钝悟需要时间的打磨,顿悟需要时间的积累 - CSDN 博客
  5. Java 8 新特性:接口的静态方法和默认方法 - Promise Sun special column - CSDN 博客
    注:说的最好的。

Guess you like

Origin www.cnblogs.com/buwuliao/p/11209567.html