Cup (11)
Cup (1)
Cup (2)
Cup (33)
Cup (3)
Cup (4)
Cups ()
Cup (33)
Cup (3)
Cup (4)
Cups ()
Inside Main ()
F (99)
The first initialization is static, the order is the code order Up-to-down, and then the method is called by itself.
The order of execution above is:
1:static cups x=new cups (); Transfer to Cups object
2:static Cup C1=new Cup (11); Transfer to cup object
3: The output cup of the Execution Cup (11);
The static Cup C2 in the 4:cups object;
5:static
{
C1=new Cup (1); Transfer to cup object Output cup (1)
C2=new Cup (2); Transfer to cup object Output cup (2)
}
The Cup C3=new Cup (33) in the 6:cups object; Output Cup (33)
7:c3=new Cup (3); Output Cup (3)
C4=new Cup (4); Output Cup (4)
8:cups ()
{
System.out.println ("Cups ()"); Output Cups ()
}
9:static cups y=new cups ();
Note that the static member in Cups has been initialized so
Static Cup C1=new Cup (11);
static Cup C2;
static{
C1=new Cup (1);
C2=new Cup (2);
}
No more execution!
The following is the same as above!