您的位置:首页 > 其它

abstract抽象类

2016-06-07 08:30 357 查看
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 抽象