java匿名对象的使用

package object_oriented04;

import object_oriented03.Person;

public class InstanceTest {
     
	public static void main(String[] args) {
     
		Phone p = new Phone();
		p.sendEmail();
		p.playgame();

		new Phone().price = 2000;
		new Phone().showPrice();// 0.00
		// *********************************************
		PhoneMall mall = new PhoneMall();
		// 匿名对象的使用
		mall.show(new Phone());
	}
}

class PhoneMall {
     
	public void show(Phone phone) {
     
		phone.sendEmail();
		phone.playgame();
	}
}

class Phone {
     
	double price;// 价格

	public void sendEmail() {
     
		System.out.println("发送邮件");
	}

	public void playgame() {
     
		System.out.println("玩游戏");
	}

	public void showPrice() {
     
		System.out.println("手机的价格为" + price);
	}
}

你可能感兴趣的:(java基础,java)