abstract class Computer{
abstract void open();
abstract void close();
void playGame(){
System.out.println("The WoW was loading...");
}
}
class WindowsComputer extends Computer{
public void open(){//抽象方法都是public,如果省略还是public,这一点不会改变。
System.out.println("The Windous was loading...");
}
public void close(){
System.out.println("The Windows was loging off...");
}
}
class MacComputer extends Computer{
public void open(){
System.out.println("The Mac was loading...");
}
public void close(){
System.out.println("The Mac was loging off...");
}
}
public class TestDemo{
public static void main(String args[]){
Computer pc = new WindowsComputer();
Computer airbook = new MacComputer();
pc.open();
airbook.open();
pc.close();
airbook.close();
pc.playGame();
airbook.playGame();
}
}
/*output
The Windous was loading...
The Mac was loading...
The Windows was loging off...
The Mac was loging off...
The WoW was loading...
The WoW was loading...
*/
abstract抽象类
最新推荐文章于 2024-08-26 17:43:48 发布