Home > Back-end >  Ask a question? _????
Ask a question? _????

Time:10-25

Public class Try
{
Int I=47;//define a global variable
Public void the call () {//define methods
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 Try () {}
Public static void main (String [] args) {
Try a t1=new Try ();
Try t2=new Try ();
T2. I=60;
System. The out. Println (" the results of the first instance object call I: "+ t1. I++);
T1. The call ();
System. The out. Println (" the results of the second instance object call I: "+ t2. I);
T2. The call ();
}
};

The output is:
The result of the first instance object call I: 47
Call the call () method
0 1 2

The results of the second instance object call I: 60
Call the call () method
0 1 2
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

Public class Try2
{
Static int I=47;//define a global variable
Public void the call () {//define methods
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 Try2 () {}
Public static void main (String [] args) {
Try2 t1=new Try2 ();
Try2 t2=new Try2 ();
T2. I=60;
System. The out. Println (" the results of the first instance object call I: "+ t1. I++);
T1. The call ();
System. The out. Println (" the results of the second instance object call I: "+ t2. I);
T2. The call ();
}
};

The output is:
The result of the first instance object call I: 60
Call the call () method
0 1 2

The results of the second instance object call I: 3
Call the call () method
0 1 2
Why is the last I 3?
  • Related