A Java question that is prone to mistakes.

Source: Internet
Author: User

// Series of output results


Class Valhold {
Public IntI= 10;
}

 
Public   Class Obparm {
Public   Static   Void Main (string argv []) {
Obparm o
= NewObparm ();
O. amethod ();
}

Public   Void Amethod () {
Int I =   99 ;
Valhold v
=   New Valhold ();
V. I
= 30 ;
Another (V, I );
System. Out. println (V. I );
}
// End of amethod
 
Public   Void Another (valhold V, Int I) {
I
= 0 ;
V. I
=   20 ;
Valhold VL
=   New Valhold ();
V
= Vl;
System. Out. println (V. I
+   "   " + I );
}
// End of another
 
}

1) 10, 0, 30

2) 20, 0, 30

3) 20, 99, 30

4) 10, 0, 20

Answer
10,0,20

The core of this problem is that when the referenced object is used as a parameter, a copy of the Object Memory Address is passed.

I understand this. This question is not difficult!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.