如何通过不同的名称在另一个类中创建一个类?

时间:2018-06-10 00:59:24

标签: java class

我有一个名为Playership的班级和另一个名为Game的班级。我希望Playership课程中的Game课程名称为播放器。我不知道该怎么做。

1 个答案:

答案 0 :(得分:0)

你要做的是这样的事情:

Math

输出

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");
    }
}