我试图在我的演员类中获取 print 方法来打印在 toString() 方法中构建的字符串。但是我不断收到错误消息。(无效的方法声明,需要返回类型)
public class actor {
private String name;
private String address;
private int age;
public actor(String name, String address, int age) {
this.name = name;
this.address = address;
this.age = age;
}
public void setName (String name) {
this.name = name;
}
public void setAddress (String address) {
this.address = address;
}
public void setAge (int age) {
this.age = age;
}
public void setFilm () {
}
public String getName () {
return name;
}
public String getAddress () {
return address;
}
public String toString (String name, int age, String address){
return name+" who's "+age+" and lives in "+address;
}
public void print (){
String a = toString();
System.out.println(a);
}
print();
}
我一直试图让这个工作很长一段时间都无济于事。