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

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());

}


}


权吖
浏览 1499回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java