When we get a program that has a superclass, a subclass, and an entry class that includes the main program to parse it, run the steps:
1. The program should start with the entry class (the class containing public, that is, 1. java files can contain only one public class, which is the entry Class).
2. You must be clear that this static main function that is contained in the Ingress class public static void Main (String args) {} is just a normal static function (class function);
3. In the Ingress class, the higher run precedence than the static main function public static void main (String args) {} is:
3.1 Static variable for ingress class (first) static
3.2 Static code block for Ingress Class (second) static {}
4. The content that can be defined in the entry class is as follows:
4.1 Entry class instance variable modifier data type variable name;
4.2 Entry class static variable modifier static data type variable name;
4.3 Entry class static method Statics return value method name () {}
4.4 Ingress class static code block statics {}
4.5 Ingress class initialization code block {}
4.6 Entry class constructor modifier class name () {}
4.7 Ingress class instance method modifier return value Method name () {}
4.8 Public static void Main (String args)
{1. The object of the Ingress class creates the Ingress class class name Reference name = new entry class name;
2. Parallel super-Class
3. The object of a parallel superclass reference subclass creates a parallel superclass class name Reference name = new Parallel subclass class name;
Parallel superclass class name reference name
Explanation: A reference variable that can be used as a superclass (class variables can be divided into: basic data type variables and reference type variables)
New Parallel Subclass class name
Explanation: Creation of 1 subclass objects
Parallel superclass class name Reference name = new Parallel subclass class name;
Explanation: The execution steps of this statement are:
1. Open up the data space of the sub-class object;
2. Assign a reference variable of the superclass to a space that holds the reference;
3. Assign the first address of the data space that opens the sub-class object to the reference variable;
Note: A reference type variable must be instantiated to open the data space after it is declared to access the object to which the variable is directed, that is, the object must be initialized before the reference is pointed to it
The procedure for the statement is similar to the conversion of the base data type: These types are from "small" to "large" (Byte,short,char)--int--long--float-double (Here we say "Large" and "small" do not refer to the number of bytes occupied, but rather the size of the range that represents the value.
When converting "small" data to "large" data:
byte B;int i=b; Long l=b; float f=b; Double d=b;
When converting "big" data to "small" data:
You can use forced type conversions. That is, you must use the following statement format: int n= (int) 3.14159/2; As you can imagine, this conversion is sure to cause a drop in overflow or precision.
.......;
.......;
}
Public static void Main (String args)
{
When instantiating an object with the New keyword.
When a static method of a class is called.
When reading or setting a static field for a class (except when it is final decorated, the result is placed in a constant pool at compile time).
Use the Java.lang.reflect package method to make reflection calls to the class.
When a subclass of a class is initialized.
When the virtual machine starts, it is marked as the startup class (the class that contains the main method).
}
My masterpiece.