zoukankan      html  css  js  c++  java
  • Java chapter04-1

    public class CPU {
    	int speed;
    	//获得speed的值
    	public void setSpeed(int m){
    		speed = m;
    	}
    	//返回speed的值
    	
    	public int getSpeed(){
    		return speed;
    	}
    	
    }
    
    public class HardDisk {
    	int amount;
    	//获得amount的值
    	public void setSpeed(int m){
    		amount = m;
    	}
    	//返回amount的值
    	
    	public int getSpeed(){
    		return amount;
    	}
    	
    }
    
    public class PC {
    	CPU cpu = new CPU();
    	HardDisk HD = new HardDisk();
    	//将参数c的值赋值给cpu
    	public void setCPU(CPU c){
    		cpu = c;
    	}
    	//将参数h的值赋值给HD
    	public void setHardDisk(HardDisk h){
    		HD = h;
    	}
    	//显示cpu的速度和硬盘的容量
    	public void show(){
    		System.out.println(cpu.speed);
    		System.out.println(HD.amount);
    	}
    }
    
    public class Test {
    	public static void main(String[] args){
    		CPU cpu = new CPU();
    		HardDisk disk = new HardDisk();
    		PC pc = new PC();
    		cpu.setSpeed(2200);
    		disk.setSpeed(200);
    		pc.setCPU(cpu);
    		pc.setHardDisk(disk);
    		pc.show();
    	}
    }
    


  • 相关阅读:
    bean
    Parcel
    其他
    XSS
    渗透 提权 常用 批处理 代码总结
    暴力攻击 PHP 脚本 初探
    CGI PL PERL脚本 提权
    ACCESS 手工注入
    shell 数组操作
    宏定义 宏参数 .
  • 原文地址:https://www.cnblogs.com/riskyer/p/3324830.html
Copyright © 2011-2022 走看看