Test类实验

package PC_TEST;

class CPU{
	int speed;
	CPU(){
		speed=0;
	}
	CPU(int k){
		speed=k;
	}
	void setSpeed(int k){
		speed=k;
	}
	int setSpeed(){
		return speed;
	}
}

class HardDisk{
	int amount;
	HardDisk(){
		amount=0;
	}
	HardDisk(int k){
		amount=k;
	}
	void setSpeed(int k){
		amount=k;
	}
	int setSpeed(){
		return amount;
	}
}

class PC{
	CPU cpu;
	HardDisk HD;
	PC(){
		cpu=new CPU();
		HD=new HardDisk();
	}
	void setCPU(CPU c){
		cpu=c;
	}
	void setHarDisk(HardDisk h){
		HD=h;
	}
	void show(){
		System.out.println("CPU speed:"
				+          +cpu.speed
						   +" HardDisk amount:"
						   +HD.amount);
	}
}

public class TEST {
	public static void main(String[] args) {
		CPU cpu=new CPU(2200);
		HardDisk disk=new HardDisk(200);
		PC pc=new PC();
		pc.setCPU(cpu);
		pc.setHarDisk(disk);
		pc.show();
	}
}


原文地址:https://www.cnblogs.com/WALLACE-S-BOOK/p/9732340.html