Java: Assigning Values to Objects

Source: Internet
Author: User

1  Packageexercise;2 3 classTank4 {5     intLevel ;6 }7 8  Public classassignment{9      Public Static voidMain (String[]args) {TenTank t1=NewTank (); OneTank t2=NewTank (); A          -T1.level=9; -t2.level=47; the          -System.out.println ("T1.level:" +t1.level+ ", T2.level:" +t2.level); -          -t1=T2; +System.out.println ("T1.level:" +t1.level+ ", T2.level:" +t2.level); -         //When you assign "from one object to another", your is actually copying a reference +         //From one place to another. A         //This means so if you say C=d for objects,you end up with both C and D pointing to at         //the object, Originally,only D pointed to. -          -T1.level=27; -System.out.println ("T1.level:" +t1.level+ ", T2.level:" +t2.level); -     } -}

Output

1 t1.level:9,t2.level:472 t1.level:47,t2.level:473 t1.level:27,t2.level:27

Java: Assigning Values to Objects

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.