题海让大学四年没有难题
白天模式登陆

题目详情

阅读程序,写出程序运行结果.//写出程序运行结果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()); }}

面向对象程序设计课程封面

学科:面向对象程序设计

时间:2026-05-15 23:48:12

Copyright © 2022 津ICP备2021001502号