码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2014-04-28 14:04:45      阅读:439      评论:0      收藏:0      [点我收藏+]

标签:com   http   class   blog   style   div   code   img   java   tar   string   

bubuko.com,布布扣

代码:

bubuko.com,布布扣
 1 /*
 2    test.java
 3 */
 4 package test;
 5 public class test {
 6     public static void main(String args[] )
 7     {
 8         CPU ccp= new CPU();
 9         HardDisk hhd=new HardDisk();
10         PC pc =new PC();
11         ccp.setSpeed(2200);
12         hhd.setAmount(200);
13         pc.setCPU(ccp);
14         pc.setHardDisk(hhd);
15         pc.show();
16     }
17 
18 }
View Code
bubuko.com,布布扣
 1 /*
 2   PC.java
 3 */
 4 package test;
 5 public class PC {
 6     CPU cpu ;
 7     HardDisk HD ;
 8     void setCPU(CPU cp)  { cpu=cp;  }
 9     void setHardDisk(HardDisk hd){ HD=hd ;}
10     void show()
11     {
12         System.out.println("CPU的Speed: "+cpu.getSpeed());
13         System.out.println("HardDisk: "+HD.getAmount());
14     }
15 }
View Code
bubuko.com,布布扣
 1 /* 
 2   CPU.java
 3 */
 4 package test;
 5 
 6 public class CPU {
 7      int speed;
 8      void setSpeed(int m){speed=m;}
 9      int getSpeed(){return speed ;}
10 }
View Code
bubuko.com,布布扣
 1 /*
 2   HardDisk.java
 3 */
 4 package test;
 5 
 6 public class HardDisk {
 7 
 8     int amount;
 9     void setAmount(int m){    amount=m;}
10     int getAmount(){return amount;}
11 }
View Code

 

java第四章编程题(初学篇),布布扣,bubuko.com

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

标签:com   http   class   blog   style   div   code   img   java   tar   string   

原文地址:http://www.cnblogs.com/gongxijun/p/3695455.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!