/*
多态的主板示例
接口的多态
*/
/*
class ZhuBanRun
{
public void run()
{
System.out.println("主板运行");
}
public void runsome(ShengKa s)
{
s.run();
s.close();
}
}
class ShengKa
{
public void run()
{
System.out.println("声卡运行");
}
public void close()
{
System.out.println("声卡关闭");
}
}
*/
interface PCI
{
public void run();
public void close();
}
class ZhuBanRun
{
public void run()
{
System.out.println("主板运行");
}
public void runsome(PCI p)//PCI p=new ShengKa
{
if(p!=null)
{
p.run();
p.close();
}
}
}
class ShengKa implements PCI
{
public void run()
{
System.out.println("声卡运行");
}
public void close()
{
System.out.println("声卡关闭");
}
}
class ZhuBan
{
public static void main(String[] args)
{
ZhuBanRun z=new ZhuBanRun();
z.runsome(new ShengKa());
}
}