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

关于方法调用问题其中m.setCar(c);与c.setMember(m);为什么不能相互调用

关于方法调用问题其中m.setCar(c);与c.setMember(m);为什么不能相互调用

权吖 2017-09-17 12:05:25
package thanks;class Member { private int mid ; private String name ; private Car car ; public Member(int mid, String name){ this.mid = mid ; this.name = name ; } public void setCar(Car car){ this.car = car ; } public Car getCar(){ return this.car ; } public String getInfo(){ return "人员编号:"+this.mid+"姓名:"+this.name ; }class Car { private Member member ; private String pname ; public Car(String pname){ this.pname = pname ; } public void setMember(Member member){ this.member = member ; } public Member getMember(){ return this.member ; } public String getInfo(){ return "车子名称"+this.pname ; } }}public class Deom1 { public static void main(String[] args) { Member m = new Member(1,"李四") ; Car c = new Car("东风") ; m.setCar(c);     //为什么调用不了啊? c.setMember(m); //为什么调用不了啊? System.out.println(m.getCar().getInfo()); System.out.println(c.getMember().getInfo()); }}
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 1498 浏览

添加回答

举报

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