第十章 Student类组合:类间的组合关系;类组合的实现方法,设计多个类相互协作程序。10.1示例程序:学生类Student关联手机类MobilePhone;双向关联
10.2相关知识:对象属性;类的组合关系。
10.3训练程序:组合关系示例:教师与桌子关联
10.4拓展知识:组合讨论;组合与封装;
[单选题]通过对象组合关系可以把两个类关联起来。(  )

选项:[错, 对]
[单选题]对象的属性既可以是基本类型,也可以是引用类型。( )

选项:[错, 对]
[单选题]学生类Student与手机类MobilePhone可以建立双向关联,手机类对象可以作为学生类的一个属性;同样学生类对象也可以作为手机类的一个属性。

选项:[错, 对]
[单选题]继承和组合都可以实现代码重用

选项:[错, 对]
[单选题]

分析程序实现代码,选择选项补全下面教师类的display()方法

Name=zhang

Salary=4580.0

Table=Rect


public class Test{       public static void main(String[] args)        {              TableInfo t=new TableInfo("Rect", 4, 100,3600);              Teacher zhang=new Teacher("zhang", 40, 4580, "VP", t);              zhang.display();       }}class Teacher{       private String name;       private int age;       private double salary;       private String professionalTitle;       private TableInfo table;       public Teacher(String name,int age,double salary,String professionalTitle,TableInfo table){              this.name = name;              this.age = age;              this.salary =salary;              this.professionalTitle = professionalTitle;              this.table = table;       }       public void display(){              System.out.println("Name=" + name);              System.out.println("Salary=" + salary);                                       }}class TableInfo{       String shape;       int legs;       int hight;       double area;       public TableInfo(String shape, int legs,int hight,double area){              this.shape = shape;              this.legs = legs;              this.hight = hight;              this.area = area;       }       public void print(){              System.out.println("Table=" + shape);       }}

选项:[System.out.println(“Table=”+ table);, 其他, System.out.println(“Table=”+ table.shape);, table.print();]

温馨提示支付 ¥3.00 元后可查看付费内容,请先翻页预览!
点赞(0) dxwkbang
返回
顶部