In the world of Java, "All Things are objects". This embodies the concept of Java design.
Since everything is object, any object reference must be initialized during the creation process. This is like the relationship between TV and remote control. The remote control is your TV reference, creating an instance of the TV, this example is the remote control. It can control all the behavior of TV. This includes part of the instantiation.
Any object instantiation must be initialized during the creation process. So-called initialization, for class objects (which we take for granted), there are constructors in class, similar to C + + constructors. For initialization of basic data types (i.e., fields), such as int,short,long,double, it is best to initialize them directly during the creation process, although these fields may be initialized by default during the creation process, but since they are all objects, we'd better initialize them to take control of the whole world.
In the process of initialization, the order of initialization is especially important. Although Java has been improved a little bit more than C + +, for example: int i = f ();
int F () {return 11;}? The function f () is required to be declared in C + +, but it is not required in Java.
And the following code:
1 Public classtest{2 3 inti = g (j);//Illegal forward reference4 5 intj =f ();6 7 intGinti) {8 9 return2 *i;?Ten One }? A - inti =f (); - the intF () {return11;} - -}?
It's not working in Java. Because you initialize I without initializing J.
Java Learning Path (iii)--thinking in Java