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();
}
}
Test类实验
最新推荐文章于 2021-06-12 21:39:50 发布