JavaDemo_0914_0006接口
interface IUSB{
public abstract boolean check();
public abstract void work();
}
//***************************************
class Computer
{
public void plugin(IUSB usb)
{
if(usb.check())
{
usb.work();
}
}
}
//*************************************
class Keyboard implements IUSB
{
public boolean check()
{
return true;
}
public void work()
{
System.out.println("Keyboard类==>开始进行码字");
}
}
//*****************************************
class Print implements IUSB
{
public boolean check()
{
return false;
}
public void work()
{
System.out.println("Print-->开始进行打印工作");
}
}
//**************************************
public class JavaDemo_0914_0006
{
public static void main(String[] args)
{
Computer computer=new Computer();
computer.plugin(new Keyboard());
computer.plugin(new Print());
}
}
封装、继承、多态,重载、覆写、向上转型、向下转型
页:
[1]