zoukankan      html  css  js  c++  java
  • java:对象赋值

     1 package exercise;
     2 
     3 class Tank
     4 {
     5     int level;
     6 }
     7 
     8 public class Assignment{
     9     public static void main(String[]args){
    10         Tank t1=new Tank();
    11         Tank t2=new Tank();
    12         
    13         t1.level=9;
    14         t2.level=47;
    15         
    16         System.out.println("t1.level:"+t1.level+",t2.level:"+t2.level);
    17         
    18         t1=t2;
    19         System.out.println("t1.level:"+t1.level+",t2.level:"+t2.level);
    20         //when you assign "from one object to another" ,your are actually copying a reference
    21         //from one place to another.
    22         //this means that if you say c=d for objects,you end up with both c and d pointing to
    23         //the object that, originally,only d pointed to .
    24         
    25         t1.level=27;
    26         System.out.println("t1.level:"+t1.level+",t2.level:"+t2.level);
    27     }
    28 }

    输出

    1 t1.level:9,t2.level:47
    2 t1.level:47,t2.level:47
    3 t1.level:27,t2.level:27
  • 相关阅读:
    Memcached安装
    linux 安装telnet
    varnish应用
    linux 安装apache
    varnishlog、Varnishstat详解
    varnish CLI管理
    varnish 子程序流程
    python3 cms识别类
    python3 fofa爬取类
    每日健康打卡
  • 原文地址:https://www.cnblogs.com/taoxiuxia/p/4423527.html
Copyright © 2011-2022 走看看