java第四章编程题(初学篇)

java第四章编程题(初学篇)

代码:

 /*
test.java
*/
package test;
public class test {
public static void main(String args[] )
{
CPU ccp= new CPU();
HardDisk hhd=new HardDisk();
PC pc =new PC();
ccp.setSpeed(2200);
hhd.setAmount(200);
pc.setCPU(ccp);
pc.setHardDisk(hhd);
pc.show();
} }
 /*
PC.java
*/
package test;
public class PC {
CPU cpu ;
HardDisk HD ;
void setCPU(CPU cp) { cpu=cp; }
void setHardDisk(HardDisk hd){ HD=hd ;}
void show()
{
System.out.println("CPU的Speed: "+cpu.getSpeed());
System.out.println("HardDisk: "+HD.getAmount());
}
}
 /*
CPU.java
*/
package test; public class CPU {
int speed;
void setSpeed(int m){speed=m;}
int getSpeed(){return speed ;}
}
 /*
HardDisk.java
*/
package test; public class HardDisk { int amount;
void setAmount(int m){ amount=m;}
int getAmount(){return amount;}
}
上一篇:SQL关于分页的sql查询语句 limit 和row_number() OVER函数


下一篇:WebStorm配置node.js调试