2021-03-10

Java basics-keyword summary

1. continue

使用场景:结束本次循环,继续下一次的循环

2. break

使用场景:终止switch或者当前循环**
  • In the select structure switch statement

  • In the loop statement

  • The existence of the use scene is meaningless
    static
    static is a modifier that can be modified:

  • Member variables, which we call class variables, or static variables, represent data shared by all objects of a certain class

  • Member methods, we call them class methods, or static methods, which represent methods that can be called without an instance object, and are called using "class name."

    • The static method of the parent class can be inherited and cannot be overridden
    • The static method of the parent interface cannot be inherited by the implementing class
  • Code block, which we call static code block, or static initialization block, is used to initialize static variables. The static code block of each class will only be executed once, and it will be executed when the class is initialized for the first time.

  • Member inner class, we call static member inner class, static inner class for short, inner class that can be used without external class instance object, in static inner class, only static members of outer class can be used

    • static cannot modify top-level classes

3. return

Destructive power is large, terminate the main method

4. this

1. The meaning of this

this represents the current object

2. Location of this

  • this in the code block and constructor related to instance initialization: represents the instance object being created, that is, who is new, and this represents who
  • This in a non-static instance method: represents the object that calls the method, that is, who is calling, this represents who.
  • this cannot appear in static code blocks and static methods

3. The format of this

(1) this. member variable name

  • When the local variable of the method has the same name as the member variable of the current object, you can add this. in front of the member variable. If there is no problem with the same name, you can omit this.
  • This. member variable will be searched from the list of member variables declared by this class first, if not found, it will go to the list of member variables inherited from the parent class and still visible in the child class.

(2) this. member method

  • When calling the member method of the current object, you can add "this." or omit it. It is omitted in actual development.
  • The member methods of the current object are first searched from the list of member methods declared by this class. If it is not found, it will be searched in the list of member methods inherited from the parent class that are still visible in the child class.

(3) this () or this (list of actual parameters)

  • Only call other constructors of this class

  • Must be in the first line of the constructor

  • If n constructors are declared in a class, at most n-1 constructors use "this([argument list])", otherwise an endless loop of recursive calls will occur

5. super

1. The meaning of super

super represents the reference from the parent class in the current object

2. The premise of using super

  • Refer to the xx of the parent class through super, which are still visible in the child class
  • Cannot use super in static code blocks and static methods

3. Use format of super

(1) super. member variables

Access the member variables of the parent class in the child class, especially when the member variable of the child class has the same name as the member variable of the parent class.
native
native: native, native
usage:

​ Can only modify methods

​ The method body code of this method is not implemented in Java language, but written in C/C++ language.

​ But for Java programmers, it can be called normally as a Java method, or subclassed to override it.

6. final

final: final, unchangeable, its usage is as follows:
1. Modified class

Indicates that this class cannot be inherited, there is no subclass
2, modification method

Indicates that this method cannot be overridden by subclasses
3. Declare constants

Final modifies a variable (member variable or local variable) to indicate that its value cannot be modified, that is, a constant. It is recommended to use capital letters for the constant name.

If a member variable is modified with final, there is no set method, and must be initialized (it can be assigned explicitly, or in the initialization block, and the instance variable can also be assigned in the constructor)
4. The modified object
address value will not change

Guess you like

Origin blog.csdn.net/qq_37698495/article/details/114648121