package person;
class Name
{
private String firstName;
private String lastName;
public Name(){}
public Name(String firstName,String lastName)
{
this.firstName = firstName;
this.firstName = lastName;
}
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;
}
}
public class Person
{
private final Name name;
public Person(Name name)
{
this.name =name;
}
public Name getName()
{
return name;
}
public static void main(String[] args)
{
Name n = new Name("哈利","波特");
Person p = new Person(n);
System.out.println(p.getName().getFirstName());
}
}
重新写了一遍 public static void main(String[] args) {
Name n = new Name("哈利","波特");
Person p = new Person(n);
System.out.println(p.getName().getFirstName());
}
就好了~好奇怪哦 之前一直显示 “波特”