原神父子
package jsu.gen.shin;
public class Player1 {
// Player(玩家)类
class Player {
String playerName;
public Player(String playerName) {
this.playerName = playerName;
}
public void playGame() {
System.out.println(playerName + "正在玩原神");
}
}
// Son(儿子)类继承自 Player(玩家)类
class Son extends Player {
public Son(String playerName) {
super(playerName);
}
public void playWithFriends() {
System.out.println(playerName + "正在和朋友一起在原神中冒险");
}
}
// 测试类
public class Test {
public void main(String[] args) {
Player father = new Player("父亲");
father.playGame(); // 输出:父亲正在玩原神
Son son = new Son("儿子");
son.playGame(); // 输出:儿子正在玩原神
son.playWithFriends(); // 输出:儿子正在和朋友一起在原神中冒险
}
}
}