/*
需求:电脑运行实例
电脑运行基于主板
*/
class Demo
{
public static void main(String[] args)
{
MainBoard mb=new MainBoard();
mb.run();
mb.useNetCar(new NetCar());//调用useNetCar,传入对象
//System.out.println("Hello World!");
}
}
class MainBoard
{
public void run()
{
System.out.println("mainboard run");
}
public void useNetCar(NetCar c)//接收对象,调用属性
{
if(c!=null)
{
c.open();
c.close();
}
}
}
abstract interface Pci
{
public abstract void open();
public abstract void close();
}
class NetCar implements Pci
{
public void open()
{
System.out.println("NetCar open");
}
public void close()
{
System.out.println("NetCar close");
}
}
class SoundCard implements Pci
{
public void open()
{
System.out.println("SoundCard open");
}
public void close()
{
System.out.println("SoundCard close");
}
} |
|