zoukankan      html  css  js  c++  java
  • 18 new关键字

    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);
        }
    }

    结果:

  • 相关阅读:
    java例题 汽油检测
    java常用api
    二分搜索法
    java例题
    java基础
    表单验证
    4.10 pm例题
    0805
    0731 框架Mybatis
    小结
  • 原文地址:https://www.cnblogs.com/CPU-Easy/p/12145201.html
Copyright © 2011-2022 走看看