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

2020-11-18 00:18

阅读:683

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

soscw.com,搜素材

代码:

soscw.com,搜素材soscw.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
soscw.com,搜素材soscw.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
soscw.com,搜素材soscw.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
soscw.com,搜素材soscw.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第四章编程题(初学篇),搜素材,soscw.com

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

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

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


评论


亲,登录后才可以留言!