如何从构造函数中打印对象?

时间:2018-11-10 19:21:25

标签: constructor package println

package Stats;

public class Players {
    private String name;
    private int RIT;
    private int TIR;
    private int PAS;
    private int REG;
    private int DEF;
    private int FIS;
    private int MED;

    public Players (String name, int RIT, int TIR, int PAS, int REG, 
    int DEF, int FIS, int MED) {
        this.name= name;
        this.RIT = RIT;
        this.TIR = TIR;
        this.PAS = PAS;
        this.REG = REG;
        this.DEF = DEF;
        this.FIS = FIS;
        MEDIA = MED;
    }

    public static void main (String[] args) {
        Players player1 = new Players ("aa", 5,3,7,1,7,9,8);
        System.out.println(player1);
    }
}

我正在尝试使用println打印所有变量,但它所做的只是打印“ Stats.Players@14c3d7e”,如果我输入println(name +“ \ n” + RIT + ....);它说我不能从非静态上下文中做到这一点。 我该如何解决?

0 个答案:

没有答案