Java Programming Chapter 4——Static method

Static method

1.static can be used to modify method.

2. A method modified by static is called static method.

3. Syntax: access modifier static returns value type method name (parameter list) {//method implementation}

4. Note: there is no order between access modifier and static.

5. Use class name, static method name (argument) (recommended) object name, static method name (argument).

6 . Precautions for static methods:

(1) Only static methods or static properties of this class can be directly accessed in static methods;

(2) Non-static members (properties and methods) of this class cannot be directly accessed in static methods.

(3) Static attributes and static methods of this class can be directly accessed in non-static methods.

(4) this/super keyword cannot be used in static methods;

(5) Static methods are allowed to be inherited, and static methods with the same name as the parent class can be defined in subclasses.