java crazy lecture (switch statement object oriented)

Type of switch expression: byte, short, int, char, enum

Curly braces: The repeated execution statement in the for while do loop cannot be a single local variable definition statement. If you want to use a loop to repeatedly define a local variable, it must be placed in curly braces to be effective.

package mianshi;

public class MainTest {
    public static void main(String args[]){
        for(int i=0;i<10;i++) {
            Cat cat = new Cat();
        }
    }
}

for loop: the initialization condition of the for loop can define multiple variables at the same time, but since only one statement is accepted, the data types of these two variables should be the same

instanceof:

The compiled type of the operand preceding the instanceof operator must be one of the following three cases:

1. same as the following class

2. The parent class of the latter class

3. Subclass of the latter class

If the compiled type of the preceding operand has nothing to do with the following type, the program will fail to compile

When run through compilation, the result is relative to the type of object actually referenced by the previous operand

Constructor:

In most cases, the program needs to use the constructor to initialize the object after applying the space for the Java object using the new keyword, but there are two ways without using the constructor:

1. Restoring java objects using deserialization

2. Copy using clone method

Static inner class vs non-static inner class

1. Non-static inner class:

1. Variables and methods cannot be declared static. (The compilation order of the class: outer class--static method or attribute--inner class, if the inner class is declared as static, it will cause a compilation order conflict. Personal understanding)

2. When instantiating, it needs to be attached to the external class. For example: B is a non-static inner class of A, instantiate B, then: AB b = new A().new B();

3. The inner class can refer to the static or non-static properties or methods of the outer class.

 

Second, the static inner class:

1. Properties and methods can be declared static or non-static.

2. Instantiate a static inner class: For example: B is the static inner class of A, AB b = new AB();

3. The inner class can only refer to the static properties or methods of the outer class.

4. If the property or method is declared as static, it can be used directly through the class name. For example, B is a static inner class of A, and b() is a static property in B, you can: ABb();

static keyword

Static methods belong to classes. If the info() method is a static method, when calling the method, such as Animal a=new Wolf() a.info()

The method at this time should be the animal method, because it is called through the animal class

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324733500&siteId=291194637