// The constructor name must be the same as the class name and has no returned value.
Class A: object {// This indicates that Class A inherits the object
Public A (): Base () {}// this indicates that the constructor of the parent class object is referenced.
}
// The concept of this is not the class itself, but the instance after the class is created
// Call the no-argument Constructor
Class B {
Public B (){}
Public B (int I): this () {}//: this () indicates that the no-argument constructor of B is called first.
Public B (string S): this () {}//: this () indicates that the no-argument constructor of B is called first.
}
// If Class B inherits from Class A, Class B calls the no-argument constructor of Class A by default. If Class A has a constructor containing parameters, you must compile a non-argument constructor in Class A display.
// If Class B needs to call a parameter constructor of Class A, the following is required:
Class {
Public (){}
Public A (int I ){}
}
Class B: {
Public B (): Base (3) {}// call the parameter constructor of Class
}
Static constructor: a static constructor is a method member that initializes a class. It is generally used to initialize static data. Static constructor cannot have parameters, modifiers, and call. When a class is loaded, the static constructor of the class is automatically called.
Main role: Initialize static members of the class
Note:
1. During the execution of a program, the static constructor can only execute once at most.
2. The static constructor is executed after the static members of the class are initialized.
3. The static constructor is executed before any static member of the class is referenced.
4. The static constructor is executed before the instance variables of any class are assigned.
Class {
Static A () {}// static Constructor
}