完成抽象类Game的3个子类中的getName和play方法。
class Main {
public static void main(String[] args) {
Monopoly monopoly = new Monopoly();
Chess chess = new Chess();
Battleships battleships = new Battleships();
monopoly.play();
chess.play();
battleships.play();
}
}
abstract class Game {
abstract String getName();
abstract void play();
}
class Monopoly extends Game {
// 返回"Monopoly"
String getName() {
}
// 输出"Buy all property."
void play() {
}
}
class Chess extends Game {
// 返回"Chess"
String getName() {
}
// 输出"Kill the enemy king."
void play() {
}
}
class Battleships extends Game {
//give "Battleships" name to game
String getName() {
return "Battleships";
}
// play method should print "Sink all ships."
void play() {
System.out.println("Sink all ships.");
}
}