当我尝试在控制台中打印某些内容时,在控制台中显示该类的目录

时间:2016-01-31 09:26:20

标签: java class

这是一个返回所需字符串和字符的类:

public class Author {

    private String name;
    private String email;
    private char gender;

    public Author(){}

    public Author (String name, String email, char gender){

            this.name = name;
            this.email = email;
            this.gender = gender;

    }

    public String getName(){        
        return name;
    }
    public String getEmail(){           
        return email;
    }

    public void setEmail(String email){         
        this.email = email;
    }

    public char getGender(){
        return gender;      
    }

    public String toStrnig(){   
        return "Name: "+ name + "\nEmail: "+ email + "\nGender: "+ gender;
    }

}

以下是呼叫姓名,电子邮件和性别的主要课程。

   public class Book {

        public static void main(String[] args) {
            Author one = new Author("Shohurh", "ghostking@mail.mail", 'm');
            System.out.println(one);
            one.setEmail("nothing");
            System.out.println(one);
        }
}

这是控制台中的结果: Library.Author@15db9742 Library.Author@15db9742

如果您能突出显示错误的代码区域,那将会很感激:

1 个答案:

答案 0 :(得分:-2)

你应该覆盖toString方法:

@Override
public String toString() {
    return name;
}