开发一个小型应用程序,该应用程序允许 DVD 和主角对象从两个不同的类中显示,但我得到以下输出。
person.Person@10ed7f5c
任何人都可以提供任何关于我出错的见解吗?
DVD类
public class DVD {
private String title;
private Person leadActor;
private int noOfStars;
public DVD (String a,Person person, int b) {
title = a;
leadActor = person;
noOfStars = b;
}
public String getTitle(){
return title;
}
public void setTitle(String title){
this.title = title;
}
public Person getLeadActor(){
return leadActor;
}
public void setLeadActor(Person leadActor){
this.leadActor = leadActor;
}
public int getNoOfStars(){
return noOfStars;
}
public void setNoOfStarts(int noOfStars){
this.noOfStars = noOfStars;
}
@Override
public String toString() {
String s = "Title " + title + "/r" + "Actor:" + leadActor + "/r" + noOfStars;
return s;
}
}
人物类
public class Person {
private String firstName;
private String lastName;
public Person (String a, String b){
firstName = a;
lastName = b;
}
public String getfirstName(){
return firstName;
}
public void setfirstName(String firstName){
this.firstName = firstName;
}
public String getlastName(){
return lastName;
}
public void setlastName(String lastName){
this.lastName = lastName;
}
}
我的班级创建对象并调用 toString
public class DvdTest {
private DVD d1;
public static void main (String [] args){
Person p2 = new Person ("Leonardo", "Decaprio");
DVD d1 = new DVD ("Inception",p2,4);
System.out.println (p2.toString());
}
}