如下内容运行时总是说找不到符号,上一个输出per.getBook().getPrice()正常编译?

class Person
{
private String name ;
private int age ;
private Book book;
public Person(String name,int age){
this.name=name;
this.age=age;
}
public String getName(){
return name;
}
public void setName(String name){
this.name=name;
}
public int getAge(){
return age;
}
public void setAge(int age){
this.age=age;
}
public Book getBook(){
return book;
}
public void setBook(Book book){
this.book=book;
}
}
class Book
{
private String title;
private float price;
private Person person;
public Book(String title,float price){
this.title=title;
this.price=price;
}
public String getTitle(){
return title;
}
public void setTitle(String title){
this.title=title;
}
public float getPrice(){
return price;
}
public void setPrice(float price)
{
this.price=price;
}
public Person getPerson(){
return person;
}
public void setPerson(Person person){
this.person=person;
}
}
public class RefDemo
{
public static void main(String[] args){
Person per=new Person("张三",30);
Book bk=new Book("java开发实战经典",59.0f);
per.setBook(bk);
bk.setPerson(per);
System.out.println("从人找到书-->姓名:"+per.getName()+",年龄:"+per.getAge()+",书名:"+per.getBook().getTitle()+",价格:"+per.getBook().getPrice()+"元。");
System.out.println("从书到人-->书名:"+bk.getTitle()+",价格:"+bk.getPrice()+"元,姓名:"+bk.getPerson().getName()+",年龄:"+bk.getPerson.getAge());
}
}



慕桂英4014372
浏览 111回答 1
1回答

开满天机

你getPerson那里少一个括号bk.getPerson().getAge());
打开App,查看更多内容
随时随地看视频慕课网APP