package car;
class Person
{
private String name;
private int age;
private Car car;
public Person(String name,int age)
{
this.name=name;
this.age=age;
}
public void setCar(Car car)
{
this.car=car;
}
public Car getCar() {
return this.car;
}
public String getInfo() {
return "姓名:"+this.name+"、年龄:"+this.age;
}
};
public class Car
{
private String name; //汽车名称
private double price; //汽车价格
private Person person;
public Car(String name,double price) {
this.name=name;
this.price=price;
}
public void setPerson(Person person)
{
this.person=person;
}
public Person getPerson()
{
return this.person;
}
public String getInfo() {
return "汽车品牌型号:"+this.name+"、汽车价值:"+this.price;
}
public static void main(String[] args) {
Person person=new Person("测试甲",30);
Car car = new Car("奔驰G50",1588800);
person.setCar(car);
car.setPerson(person);
System.out.println(person.getCar().getInfo());
System.out.println(car.getPerson().getInfo());
// TODO 自动生成的方法存根
}
}