Two references point to the same heap memory

Posted lzp123456-

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Two references point to the same heap memory相关的知识,希望对你有一定的参考价值。

Phone类
package com.itheima_03;
/*
 * 手机类
 */
public class Phone {
    String brand;
    int price;
    String color;
    
    public void call(String name) {
        System.out.println("给"+name+"打电话");
    }
    
    public void sendMessage() {
        System.out.println("群发短信");
    }
}
Phone的测试类:
package com.itheima_03;
/*
 * 手机类的测试类
 */
public class PhoneDemo3 {
    public static void main(String[] args) {
        Phone p = new Phone();
        p.brand = "OPPO";
        p.price = 2999;
        p.color = "白色";
        System.out.println(p.brand+"---"+p.price+"---"+p.color);
        
        Phone p2 = p;
        p2.brand = "魅族";
        p2.price = 1999;
        p2.color = "蓝色";
        System.out.println(p.brand+"---"+p.price+"---"+p.color);
        System.out.println(p2.brand+"---"+p2.price+"---"+p2.color);
    }
}

内存图:

技术分享图片

 

以上是关于Two references point to the same heap memory的主要内容,如果未能解决你的问题,请参考以下文章

Can't resolve reference to bean 'dataSource' in parent factory: no parent factory availa

leetcode1347. Minimum Number of Steps to Make Two Strings Anagram

freemind 运行就报错~"The registry refers to a nonexistent Java Runtime Environment installation or t

LeetCode 1347. Minimum Number of Steps to Make Two Strings Anagram

Two Points问题--之LeetCode 11题

A. Two distinct points