为什么返回值与我尝试调用的值不同?

时间:2018-10-11 21:44:14

标签: java

当我尝试打印竞争对手名称时,我将返回此值 名称@ 75b84c92 谁能解释为什么?我是Java的完整初学者,这项作业应在下周完成。我的代码中没有错误,但不明白为什么不打印名称。我不确定我是否在打电话另一个班上有问题

有人可以帮忙吗?

public class Competitor {
//create instance variables
    private int competitorNumber;
    private Name competitorName;
    private String competitorLevel;
    private String competitorCountry;
    int[] competitorScore;


    //create constructor 

    public Competitor(int number, Name name, String level, String      country, int[] score) {
        competitorNumber = number;
        competitorName = name;
        competitorLevel = level;
        competitorCountry = country;
        competitorScore = score;

    }



    public Name  getCompetitorName() {
        return competitorName;
    }

    public class CompetitorMain {

    public static void main(String[] args) {




        int[] SRScores = {4,5,4,3,3};
        Competitor sonkeRothenburger = new Competitor (104, new Name    ("Sonke", "Rothenburger"), "Inter 1", "Germany", SRScores);

        int[] LGScores = {5,4,5,4,3};
        Competitor lauraGraves = new Competitor (105, new Name ("Laura", "Verdades"), "Inter 1", "USA", LGScores);

    System.out.println(sonkeRothenburger.getCompetitorName());


public class Name {

private String firstName;
private String middleName;
private String lastName;




    public String getFullName() {
        if (middleName.isEmpty()) { return "" + firstName + lastName;
        }
        else {return "" + firstName + middleName + lastName;
        }
    }

public Name(String firstName,String lastName, String middleName) {
    this.firstName = firstName;
    this.lastName = lastName;
    this.middleName = middleName;
}
public Name(String firstName, String lastName) {
    this.firstName = firstName;
    this.lastName = lastName;
    this.middleName = "";
}

1 个答案:

答案 0 :(得分:0)

您尝试打印对象,但没有覆盖toString()。 覆盖方法或获取对象的所有部分并打印。