标签:放弃 bsp book col -- stat static [] sys
class Book { String name; double price; public void getInfo() { System.out.println("书名:" + name + " 价格是:" + price + "元"); } } public class Demo { public static void main(String args[]) { //创建两个不同的Book对象 Book bk1 = new Book(); Book bk2 = new Book(); //给bk1对象初始化 bk1.name = "Java从入门到放弃"; bk1.price = 39.9; //引用传递 bk2 = bk1; //改变bk2引用的name的值 bk2.name = "Java学不会"; //输出bk1的值,可以看到bk1的值也改变了,因为两个对象指向的是同一块堆内存 bk1.getInfo(); } } /*---------------------------------- F:\Code>java Demo 书名:Java学不会 价格是:39.9元 F:\Code>*/
标签:放弃 bsp book col -- stat static [] sys
原文地址:https://www.cnblogs.com/dododo70/p/10312109.html