Download Java and java Official Website

Source: Internet
Author: User

Download Java and java Official Website

For the value assignment operation "=", the actual value is stored for the basic data type,
"Assigning an object to another object" means copying a reference from one place to another.
The object is"Alias symptom".
Example:

//: Main. javaclass FloatType {float f;}/*** alias mechanism example */public class Main {public static void main (String [] args) {FloatType f1 = new FloatType (); floatType f2 = new FloatType (); f1.f = 4; f2.f = 8; System. out. println ("f1.f =" + f1.f + ", f2.f =" + f2.f); f1.f = 16; f2.f = 32; System. out. println ("f1.f =" + f1.f + ", f2.f =" + f2.f); f1 = f2; // value assignment operation f2.f = 64; // alias phenomenon, the value of f1.f is also changed to System. out. pr Intln ("f1.f =" + f1.f + ", f2.f =" + f2.f) ;}/ *** Output: * f1.f = 4.0, f2.f = 8.0 * f1.f = 16.0, f2.f = 32.0 * f1.f = 64.0, f2.f = 64.0 *///:~

In a method call, an object is passed as a parameter to a method. In fact, passing a reference also produces an alias.

//: Main. javaclass FloatType {float f;}/*** method call alias Mechanism */public class Main {static void change (FloatType of) {. f = 32;} public static void main (String [] args) {FloatType of = new FloatType ();. f = 4; System. out. println (". f = "+. f); change (of); // the reference of the method call is passed to System. out. println (". f = "+. f) ;}}/*** Output: *. f = 4.0 *. f = 32.0 *///:~

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.