为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

慕桂英4014372 2022-05-08 13:09:23
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());}}
查看完整描述

1 回答

?
开满天机

TA贡献1786条经验 获得超13个赞

你getPerson那里少一个括号
bk.getPerson().getAge());

查看完整回答
反对 回复 2022-05-10
  • 1 回答
  • 0 关注
  • 110 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信