两个对象使用同一个方法

代码

package 包名
public class Demo01PhoneOne {
	public static void main(String[]args){
        
	Phone one=new Phone();
	System.out.println(one.brand);//null
	System.out.println(one.price);//0.0
	System.out.println(one.color);//null
	System.out.println("=========");
	one.brand="苹果";
	one price =8388.0;
	one.co1or="黑色";
	System.out.print1n(one.brand);//苹果
	System.out.println(one.price);//8388.0
	System.out.print1n(one.co1or);//黑色
	System.out.println("=========");
    one.call("乔布斯");//给乔布斯打电话
	one sendMessage();//群发短信
        
    Phone two=new Phone();
	System.out.println(two.brand);//null
	System.out.println(two.price);//0.0
	System.out.println(two.color);//null
	System.out.println("=========");
	two.brand="三星";
	two price =5999.0;
	two.co1or="蓝色";
	System.out.print1n(two.brand);//三星
	System.out.println(two.price);//5999.0
	System.out.print1n(two.co1or);//蓝色
	System.out.println("=========");
    one.call("欧巴");//给欧巴打电话
	one sendMessage();//群发短信
	}
}

内存图
在这里插入图片描述

展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 游动-白 设计师: 上身试试
应支付0元
点击重新获取
扫码支付

支付成功即可阅读