我有一个名为Playership
的类和另一个名为Game
的类。我想Playership
班级Game
以玩家的名字命名。我不知道该怎么做。
您要做的是这样的:
class Playership {
public Playership() {
System.out.println("This is a playership, please be careful!");
}
}
class Game {
private Playership playership;
public Game() {
System.out.println("Starting the game...");
this.playership = new Playership();
System.out.println("I have a playership now.");
}
}
public class MyClass {
public static void main(String args[]) {
Game game = new Game();
System.out.println("The end of the Game");
}
}
输出将是
Starting the game...
This is a playership, please be careful!
I have a playership now.
The end of the Game