首页 > 其他 > 详细

18 new关键字

时间:2020-01-03 15:59:35      阅读:71      评论:0      收藏:0      [点我收藏+]

 

package com.wys.javaoop;

public class CatTest {
    public static void main(String[] args) {
        Cat one = new Cat();
        Cat two = one;  //此时 two 和 one 都指向同一个实例化的对象

        one.name = "mcgonagall";
        one.month = 2;
        one.weight = 1000;
        one.species = "英国短毛猫";

        two.name = "cat2";
        two.month = 3;
        two.weight = 3000;
        two.species = "美国短毛猫";

        System.out.println("名字:" + one.name);
        System.out.println("年龄:" + one.month);
        System.out.println("体重:" + one.weight);
        System.out.println("品种:" + one.species);
        System.out.println("-----------------------------");
        System.out.println("名字:" + two.name);
        System.out.println("年龄:" + two.month);
        System.out.println("体重:" + two.weight);
        System.out.println("品种:" + two.species);
    }
}

结果:

技术分享图片

18 new关键字

原文:https://www.cnblogs.com/CPU-Easy/p/12145201.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!