单项选择题
【分录题】(7-7)阅读程序,写出程序运行结果。 //写出程序运行结果 class Leg {// 腿 private int length; public Leg(int length) { this.length = length; } public int getLength() { return length; } public void setLength(int length) { this.length = length; } } class Head {// 头 private String type;// 类型 public Head(String type) { this.type = type; } public String getType() { return type; } public void setType(String type) { this.type = type; } } class Person { private String name;// 姓名 private char sex;// 性别 private Leg leg;//腿 private Head head;//头 public Person(String name) { this.name = name; } public Person(String name, char sex) { this(name); this.sex=sex; } public Leg getLeg() { return leg; } public void setLeg(Leg leg) { this.leg = leg; } public Head getHead() { return head; } public void setHead(Head head) { this.head = head; } public String getPerson() { StringBuffer sb=new StringBuffer(); sb.append(this.name+leg.getLength()+head.getType()); return sb.toString(); } } //测试类 public class DogDemo { public static void main(String[] args) { Leg leg=new Leg(30); Head head=new Head("国字脸"); Person zhangfei=new Person("张飞","男"); zhangfei.setLeg(leg); zhangfei.setHead(head); leg.setLength(80); System.out.println(zhangfei.getPerson()); } }
A.lengthB.length
C.type
D.type
E.name
F.sex=sex;
G.leg
H.head
I.append(this.name+leg.getLength()+head.getType());
J.toString();
K.setLeg(leg);
L.setHead(head);
M.setLength(80);
N.out.println(zhangfei.getPerson());
点击查看答案&解析
