Home > Back-end >  Small white pure self-study questions
Small white pure self-study questions

Time:09-18

Public class TransferProperty {
Int I=47;
Public void the call () {
System. The out. Println (" call call () method ");
for(i=0; I<3; I++) {
System. The out. Print (I + "");
If (I==2) {
System. The out. Println (" \ n ");
}
}
}
Public TransferProperty () {
}
Public static void main (String [] args) {
TransferProperty t1=new TransferProperty ();
TransferProperty t2=new TransferProperty ();
T2. I=60;
System. Out. Println (" the first instance objects called variable (I) : "+ t1, I);
T1. The call ();
System. Out. Println (" the second instance objects called variable (I) : "+ t2. I);
T2. The call ();
}

}

This code output for:
The results of the first instance objects called variable I: 47
Call the call () method
012

The second instance objects called variable I results: 60
Call the call () method
012


There are two problems, the first: why t1. I=47
The second: according to the code sequence, the output sequence should be:
"Call the call () method
012

Call the call () method
012

The results of the first instance objects called variable I: 47
The second instance objects called variable I results: 60 "
Why code the output sequence has changed?

CodePudding user response:

T1. I you don't have the assignment is the default value of 47
In accordance with the order of the code you want to order is not right
Because you are first and then in the printed character

CodePudding user response:

Not completely top-down implementation method code, many times by the calling sequence, where think call method is called,

CodePudding user response:

The first question: did you initialization time to define the I, in the new class members, int I=47, so the t1 i.=47
The second question:
System. Out. Println (" the first instance objects called variable (I) : "+ t1, I);
When the code execution to this step, you need use t1. I value, this time it will go to call TransferProperty, initialize the t1 this class member,
So I=47,
So output: the first instance object call variable I results: 47
Then calls the t1. The call ()
Output: call the call () method
012

Similarly t2

CodePudding user response:

Thank you bosses, I see
  • Related