我想重写 toString() 方法以显示用户名,但 Name 是 User 类的内部类,所以我该如何打印它。
public class User
{
public static class Name
{
private String _first, _last;
public String getFirst() { return _first; }
public String getLast() { return _last; }
public void setFirst(String s) { _first = s; }
public void setLast(String s) { _last = s; }
}
private Name _name;
public Name getName() { return _name; }
public void setName(Name n) { _name = n; }
@Override
public String toString()
{
return "";//How to print first name and last name here
}
}