Java 2 实用教程 第六版(清华大学出版社)第四章编程题

Java 2 实用教程 第六版(清华大学出版社)第四章编程题_第1张图片

public class HardDisk
{
	int amount;
	void setAmount(int m)
	{
		amount=m;
	}
	int getAmount()
	{
		return amount;
	}
}

 

public class Test
{
	public static void main(String args[])
	{
		CPU cpu=new CPU();
		cpu.setSpeed(2200);
		HardDisk disk=new HardDisk();
		disk.setAmount(200);
		PC pc=new PC();
		pc.setCPU(cpu);
		pc.setHardDisk(disk);
		pc.show();
		
	}
}
public class PC
{
	CPU cpu;
	HardDisk HD;
	void setCPU(CPU c)
	{
		cpu=c;
	}
	void setHardDisk(HardDisk h)
	{
		HD=h;
	}
	void show()
	{
		System.out.println("CPU的速度为:"+cpu.speed);
		System.out.println("CPU的速度为:"+HD.amount);		
		
	}
}
public class CPU
{
	int speed;
	void setSpeed(int m)
	{
		speed=m;
	}
	int getSpeed()
	{
		return speed;
	}
}

你可能感兴趣的:(练习,java,开发语言)