阅读以下说明和java代码,将应填入(n)处的字句写在对应栏内。[说明]本程序使用类来管理员工的通讯地址信息。已知程序的输出为:输出记录:5姓名:王丽华街道地址:中华路15号市:襄樊市省:湖北省邮政编码:430070[Java代码]public class Employee{protected String (1);protected String street;protected String city;protected String prov;protected String post;protec

题目

阅读以下说明和java代码,将应填入(n)处的字句写在对应栏内。

[说明]

本程序使用类来管理员工的通讯地址信息。已知程序的输出为:

输出记录:5

姓名:王丽华

街道地址:中华路15号

市:襄樊市

省:湖北省

邮政编码:430070

[Java代码]

public class Employee{

protected String (1);

protected String street;

protected String city;

protected String prov;

protected String post;

protected int no;

public Empbyee(){}

public Employee(String name,String street,String city,String prov,String post, (2) ){

this.name=name;

this.street=street;

this.city=city;

this.prov=prov;

this.post=post;

this.no=no;

}

public static void main(String[]args){

Employee emp=new Employee(“王华”,“中华路15号”,“武汉市”,“湖北省”,“430070”,1);

emp.changeName(“王丽华”);

(3) (“襄樊市”);

emp.changeNo(5);

(4);

}

void changeName(String name){this.name=name;}

void changeStreet(String street){this.street=street;}

void changeCity(String city){this.city=city;}

void changeProv(String prov){this.prov=prov;}

void changeNo(int no){(5);}

void display(){

System.out.println(“输出记录:”+this.no);

System.out.Println(“姓名:”+this.name);

System.out.println(“街道地址:”+this.street);

System.out.println(“市:”+this.city);

System.out.println(“省:”+this.prov);

System.out.println(“邮政编码:”+this.post);

}

}


相似考题

3.阅读下列说明、图和Java代码,将应填入(n)处的字句写在对应栏内。【说明】已知对某载客车辆(Car)进行类建模,如图7-1所示,其中类Engine表示发动机引擎,类Wheel表示车轮,类Body表示车身,类Driver表示司机,类Passenger表示乘客。【Java代码】class Body{ //此处代码省略 ); //车身类class Passenger{ //此处代码省略 )/ //乘客类class Wheel{ //此处代码省略 ); //车轮类class Driver{ //司机类public String name; //表示第几路公交车司机public Driver(String driverName){name = driverName/) //构造函数};class Engine{//引擎类public String engineNo;//引擎编号public Engine(String engineNo){this.engineNo=engineNo;)//构造函数};public class Car{//汽车类static final int(1)=7; //定义最多载客数static final int MAX WHEELS =5; //定义最多轮胎数protected Engine engine;protected Driver driver;protected Body body=new Body();protected Wheel[] wheels;protected Passenger[]passengers;public Car(Driver driver){ //构造函数(2).driver=driver;engine=new Engine("TX6536型号引擎");wheels=new Wheel[MAX WHEELS];passengers=new Passenger[MAX_PASSENGERS];for(int index=0;index<MAX_WHEELS;index++){wheels[index]=new Wheel();}for(int index=0;index<MAX_PASSENGERS;index++){passengers[index]=null;}}int getPassengerNumber(){//获取车上乘客数量//此处代码省略}void getOnPassenger(Passenger aPassenger){//乘客上车//此处代码省略}void run(){ //开车if((3)){System.out.println("司机尚未上车!");return;}//此处代码省略}public static void main(String args[]){Driver driver=new Driver("第五路公交车司机");Car car=new Car((4));for (int index = 0 ; index < MAX_PASSENGERS; index ++)car.getOnPassenger((5) Passenger());car.run();}}

更多“阅读以下说明和java代码,将应填入(n)处的字句写在对应栏内。[说明]本程序使用类来管理员工的通讯地址信息。已知程序的输出为:输出记录:5姓名:王丽华街道地址:中华路15号市:襄樊市省:湖北省邮政编码:430070[Java代码]public class Employee{protected String (1);protected String street;protected String city;protected String prov;protected String post;protec”相关问题
  • 第1题:

    阅读以下说明、Java代码,将应填入(n)处的字句写在对应栏内。

    【说明】

    本程序输出10000之内的所有完全数。完全数是指等于其所有因子和(包括1,但不包括这个数本身)的数。例如:6=1×2×3,6=1+2+3,则6是一个完全数。

    【程序】

    public class PerfectNum

    {

    Public static void main(String args[])

    {

    int count=1;

    for(int i=1; i<10000; i++)

    {

    int y=0;

    for(int j=1; j<i; j++)

    if((1))

    y=(2)

    if((3))

    {

    System.out.print( (4) +String.valueOf('\t'));

    (5)

    If(count%3==0)

    System.out.printin();

    }

    }

    }


    正确答案:(1)i%j==0 (2)y+j; (3)y==i (4)i (5)count++;
    (1)i%j==0 (2)y+j; (3)y==i (4)i (5)count++; 解析:本题考查用Java语言的语法、结构及算法的具体实现。
     题目要求我们输出10000之内的所有完全数,而完全数是指等于其所有因子和数。要想求出1到10000中的所有完全数,我们需要从1开始对每个数进行求解,在判断一个数是否是完全数时,首先要求出其所有因子,再求其因子的和,从而通过判断因子的和与该数是否相等来确定该数是否为完全数。一个数的因子是指能被该数整除的数。
    下面我们来看代码,定义了一个类PerfectNum来实现输出10000之内的所有完全数。在类中有一个主入口函数,在函数体中首先声明了一个整型变量count并赋初值1,接下来是一个循环语句,其作用是用来对从1到10000之间的数逐个求解。在这个循环体里面又有一个循环,结合我们的分析和程序来看,此循环的功能是求得每个数的所有因子并计算其和,第(1)空就是在这个循环体下面,是一个条件语句的判断条件,其作用是判断变量i中的数值是否是变量i中数的因子,判断是否是因子的方法是取余,看结果是否为0。因此,第(1)空的答案是i%j==0。
    第(2)空是紧接着第(1)空来的,如果变量i中的数值是变量i中数的因子,则执行此空,那肯定是对因子求和,其和存放在变量y中,那么此空答案是y+1。
    第(3)空也是一个条件语句的判断条件,结合后面的程序,我们可以知道,此处是判断该数因子的和是否等于该数,如果是,则执行后面的输出语句:不是,则进入下一个循环。因此,此空答案是y==i。
    第(4)空在输出语句中,这考查我们对Java语言中输出语句的熟悉情况,如果熟悉的话,此空很简单,答案是i或y。
    第(5)空是用来记录从1到10000之间完全数的个数,有一个记录的变量count,在每次输出一个完全数后只要我们对变量count加1即可。因此,此空答案为count++。

  • 第2题:

    阅读下列说明和Java代码,将应填入 (n) 处的字句写在答题纸的对应栏内。

    【说明】

    现欲构造一文件/目录树,采用组合(Composite)设计模式来设计,得到的类图如6—8所示:

    【Java代码】

    import JavA.util.ArrayList;

    import JavA.util.List;(1)class AbstractFile{

    protected String name;

    public void printName(){System.out.println(name);}

    public abstract boolean addChild(AbstractFile file);

    public abstract boolean removeChild(AbstractFile file);

    public abstract ListgetChildren {};

    }

    class File extends AbstractFile{

    public File(String name)(this.name=name;}

    public boolean addChild(AbstractFile file){return false;}

    public boolean removeChild(AbstractFile file){return false;}

    public ListgetChildren(){return (2) ;)

    }

    clasS Folder extends AbstractFile{

    private ListchildList;

    public Folder(String name){

    thiS.name=name;

    this.childList=new ArrayList{};

    }

    public boolean addChild(AbstractFile file){return childList.add(file);}

    public boolean removeChild(AbstractFile file){return childList.remove(file);

    public (3)getChildren(){return (4) ;)

    }

    public class Client{

    public static void main(String[]args){

    //构造一个树形的文件/目录结构

    AbstractFile rootFolder=new Folder(“C:\”’);

    AbstractFile compositeFolder=new Folder(”composite”);

    AbstractFile windowsFolder=new Folder(”windows”);

    AbstractFile file=new File(”TestComposite.java”);

    rootFOlder.addChild (compositeFolder);

    rootFolder.addChiid(windowsFolder);

    compositeFolder.addChild(file);

    //打印目录文件树

    printTree(rootFolder);

    }

    private static void printTree(AbstractFile ifile){

    ifile.PrIntName();

    Listchildren:ifile.getChildren ();

    if(chiidren==null)return;

    for(AbstractFile file:children){(5) ;

    }

    }

    }

    该程序运行后输出结果为:

    C:\

    composite

    TestComposite.java

    Windows


    正确答案:(1)Abstract(2)null(3)List(4)childList(5)printTree(file)
    (1)Abstract(2)null(3)List(4)childList(5)printTree(file) 解析:Composite模式定义:将对象以树型结构组织起来,以达成“部分-整体”的层次结构,使得客户端对单个对象和组合对象的使用具有一致性。Composite比较容易理解,想到Composite就应该想到树型结构图。组合体内这些对象都有共同接口,当组合体一个对象的方法被调用执行时,Composite将遍历(Iterator)整个树形结构,寻找同样包含这个方法的对象并实现调用执行。AbstractFile为一个抽象文件类,其作用主要是实现对文件或者文件夹的抽象。文件类File继承自AbstractFile。File(stringname)为File类的一个属性,用于获取文件名称。Add-child方法用来给一个目录增加子目录或文件。Removechild方法用于删除一个目录的子目录或文件。Getchildren方法用于获取一个目录或文件,所以返回值类型应该是一个列表形式的AbstractFile,但文件本身不包括子目录,故返回NUIJIJ。Fold类表示一个文件夹,属性Folder用于获取文件夹名称,Getchildren方法返回值应为List型的AbstractFile对象指针。

  • 第3题:

    阅读下列说明、图和Java代码,填补空缺。

    [说明]

    已知对某载客车辆(Car)进行类建模,如图13-2所示,其中类Engine表示发动机引擎,类Wheel表示车轮,类Body表示车身,类Driver表示司机,类Passenger表示乘客。

    [Java代码]

    class Body{ //此处代码省略 }; //车身类

    class Passenger{ //此处代码省略 }; //乘客类

    class Wheel{ //此处代码省略 }; //车轮类

    class Driver{ //司机类

    public String name; //表示第几路公交车司机

    public Driver(String driverName){name=driverName; }

    //构造函数

    };

    class Engine{ //引擎类

    public String engineNo; //引擎编号

    public Engine(String engineNo){this.engineNo=engineNo; }

    //构造函数

    };

    public class Car{ //汽车类

    static final int (1) =7; //定义最多载客数

    static final int MAX_WHEELS=5; //定义最多轮胎数

    protected Engine engine;

    protected Driver driver;

    protected Body body=new Body( );

    protected Wheel[]wheels;

    protected Passenger[]passengers;

    public Car(Driver driver){ //构造函数

    (2) .driver=driver;

    engine=new Engine("TX6536型号引擎");

    wheels = new Wheel[MAX_WHEELS];

    passengers=new Passenger[MAX_PASSENGERS];

    for(int index=0; index<MAX_WHEELS; index++){

    wheels[index]=new Wheel( );

    }

    for(int index=0; index<MAX_PASSENGERS; index++){

    passengers[index]=null;

    }

    }

    int getPassengerNumber( ){ //获取车上乘客数量

    //此处代码省略

    }

    void getOnPassenger(Passenger aPassenger ){

    //乘客上车

    //此处代码省略

    }

    void run( ){ //开车

    if( (3) )(System.out.printin("司机尚未上车!"); return; }

    //此处代码省略

    }

    public static void main(String args[]){

    Driver driver=new Driver("第五路公交车司机");

    Car car=new Car( (4) );

    for(int index=0; index <MAX_PASSENGERS; index++)

    car.getOnPassenger( (5) Passenger( ));

    car.run( );

    }

    }


    正确答案:MAX_PASSENGERS this driver==null driver new
    MAX_PASSENGERS this driver==null driver new 解析:根据题意可得,程序代码中空(1)处定义最多载客数目,从后面的程序代码可得MAX_PASSENGERS用来定义最多载客数目,所以空(1)处应该为MAX_PASSENGERS。由于参数的名称driver与成员变量的名称相同,因此需要加上this,所以空(2)处为this。空(3)处主要用于判断司机是否上车,可以通过driver是否等于null进行判断。空(4)处用于新建一个汽车对象,其构造方法中需要一个司机对象driver,所以空(4)处应为driver。函数getOnPassenger的参数应该是乘客对象,因此要构造一个乘客对象,所以空(5)处为new。

  • 第4题:

    阅读下列说明和 C++代码,将应填入(n)处的字句写在答题纸的对应栏内。 【说明】 某快餐厅主要制作井出售儿童套餐,一般包括主餐(各类比萨)、饮料和玩具,其餐品种类可能不同,但其制作过程相同。前台服务员(Waiter)调度厨师制作套餐。现采用生成器(Builder) 模式实现制作过程,得到如图 5-1 所示的类图。图5-1 类图 【C++代码】 include<iostream> include <string> using namespace std; class Pizza { private: string parts; public: void setParts(string parts) { this->parts=parts; } string getParts() { return parts; } }; class PizzaBuilder { protected:Pizza* pizza; public: Pizza* getPizza() { retum pizza; } void createNewPizza() { pizza = new Pizza(); } ( 1 ); } class HawaiianPizzaBuilder :public PizzaBuilder { public: void buildParts() { pizza->setParts("cross +mild + ham&pineapple"); } }; class SpicyPizzaBuider: public PizzaBuilder { public: void buildParts() { pizza->setParts("pan baked +hot + ham&pineapple"); } } Class Waiter{ Private: PizzaBuilder* pizzaBuilder; public: void setPizzaBuilder(PizzaBuilder* pizzaBuilder) { /*设置构建器*/ ( 2 ) } Pizza* getPizza() { return pizzaBuilder->getPizza(); } void construct() { /*构建*/ pizzaBuilder->createNewPizza(); ( 3 ) } }; int main(){ Waiter*waiter=new Waiter(); PizzaBuilder*hawaiian pizzabuilder=new HawaiianPizzaBuilder() ( 4 ); ( 5 ); cout<< "pizza: "<< waiter->getPizza()->getParts()<< endl; } 程序的输出结果为: pizza: cross + mild + ham&pineapple


    正确答案:(1)virtual void buildParts()
    (2)this->pizzaBuilder=pizzaBuilder
    (3)pizzaBuilder->buildParts()
    (4)waiter->setPizzaBuilder(hawaiian_pizzabuilder)
    (5)waiter->construct()

  • 第5题:

    试题七(共 15 分)

    阅读下列说明、图和Java代码,将应填入 (n) 处的字句写在答题纸的对应栏内。

    [说明]

    已知对某载客车辆(Car)进行类建模,如图 7-1所示,其中类 Engine 表示发动机引擎,类 Wheel 表示车轮,类 Body 表示车身,类 Driver 表示司机,类 Passenger 表示乘客。

    [Java 代码]

    class Body{ //此处代码省略 }; //车身类

    class Passenger{ //此处代码省略 }; //乘客类

    class Wheel{ //此处代码省略 }; //车轮类

    class Driver{ //司机类

    public String name; //表示第几路公交车司机

    public Driver(String driverName){name = driverName;} //构造函数

    };

    class Engine{ //引擎类

    public String engineNo; //引擎编号

    public Engine(String engineNo){ this.engineNo = engineNo; } //构造函数

    };

    public class Car{ //汽车类

    static final int (1) = 7; //定义最多载客数

    static final int MAX_WHEELS = 5; //定义最多轮胎数

    protected Engine engine;

    protected Driver driver;

    protected Body body = new Body();

    protected Wheel[] wheels;

    protected Passenger[] passengers;

    public Car(Driver driver){ //构造函数

    (2) .driver = driver;

    engine = new Engine("TX6536 型号引擎");

    wheels = new Wheel[MAX_WHEELS];

    passengers = new Passenger[MAX_PASSENGERS];

    for (int index = 0; index < MAX_WHEELS; index++){

    wheels[index] = new Wheel();

    }

    for (int index = 0; index < MAX_PASSENGERS; index++){

    passengers[index] = null;

    }

    }

    int getPassengerNumber(){ //获取车上乘客数量

    //此处代码省略

    }

    void getOnPassenger(Passenger aPassenger ){ //乘客上车

    //此处代码省略

    }

    void run(){ //开车

    if( (3) ){ System.out.println("司机尚未上车!"); return;}

    //此处代码省略

    }

    public static void main(String args[]){

    Driver driver = new Driver("第五路公交车司机");

    Car car = new Car( (4) );

    for (int index = 0 ; index < MAX_PASSENGERS; index ++)

    car.getOnPassenger( (5) Passenger());

    car.run();

    }

    }


    正确答案:

  • 第6题:

    试题六(共15分)

    阅读以下说明和Java代码,填补Java代码中的空缺(1)~(6),将解答写在答题纸的对应栏内。

    【说明】

    己知某公司按周给员工发放工资,其工资系统需记录每名员工的员工号、姓名、工资等信息。其中一些员工是正式的,按年薪分周发放(每年按52周计算);另一些员工是计时工,以小时工资为基准,按每周工作小时数核算发放。

    下面是实现该工资系统的Java代码,其中定义了四个类:工资系统类PayRoll,员工类Employee,正式工类Salaried和计时工类Hourly,Salaried和Hourly是Employee的子类。

    【Java代码】

    abstract class Employee{

    protected String name; //员工姓名

    protected int empCode; //员工号

    protected double salary; //周发放工资

    public Employee(int empCode, String name){

    this.empCode= empCode;

    this.name= name;

    }

    public double getSalary(){

    return this.salary;

    }

    public abstract void pay();

    }

    class Salaried (1) Employee{

    private double annualSalary;

    Salaried(int empCode, String name, double payRate){

    super(empCode, name);

    this.annualSalary= payRate;

    }

    public void pay(){

    salary= (2) ;//计算正式员工的周发放工资数

    System.out.println(this.name+":"+this.salary);

    }

    }

    class Hourly (3) Employee{

    private double hourlyPayRate;

    private int hours;

    Hourly(int empCode, String name, int hours, double payRate){

    super(empCode, name);

    this.hourlyPayRate= payRate;

    this.hows= hours,

    }

    public void pay(){

    salary= (4) ;//计算计时工的周发放工资数

    System.out.println(this.name+":"+this.salary);

    }

    }

    public class PayRoll{

    private (5) employees[]={

    new Salaried(l001,"Zhang San", 58000.00),

    //此处省略对其他职工对象的生成

    new Hourly(1005,"Li", 12, 50.00)

    };

    public void pay(Employee e[]){

    for (int i=0;i<e.length; i++){

    e[i].pay();

    }

    }

    public static void main(String[] args)

    {

    PayRoll payRoll= new PayRoll();

    payRoll.pay( (6) );

    double total= 0.0;

    for (int i=0;i<payRoll.employees.length; i++){//统计周发放工资总额

    total+=payRoll.employees[i].getSalary();

    }

    System.out.println(total);

    }

    }


    正确答案:
    (1)extends
    (2)annualSalary/52
    (3)extends
    (4)hours*hourlyPayRate
    (5)~(6)的解答可为以下两种之一:
    (5)Employee
    (6)payRoll.employees

    (5)staticEmployee
    (6)employees或payRoll.employees

  • 第7题:

    阅读以下说明和Java代码,将应填入( )处的字句写在答题纸的对栏内。 【说明】 现如今线下支付系统可以使用现金(Cash)、移动支付、银行卡( Card)(信用卡( Creditcard)和储蓄卡( Debitcard))等多种支付方式( PaymentMethod)对物品(tem)账单(Bill)进行支付。图 5-1 是某支付系统的略类图。

    import java. util. Array List;import java. util. List;interface PaymentMethod { Public ( 1 )}∥cash、 Debitcard和ltem 实现略,ltem中getPrice( )取当前物品对象的价格abstract class Card (2) { private final String name, num; public Card(string name, String num){this.name= name; this, num = num; } @Overide public String toString ( ) { return String. format(“%s card[name = %s, num =%s}”, this. getType( ), name, num); @override public void pay(int cents) { System. out. printin(“Payed"+ cents+"cents using"+toString( )); this, execute Transaction(cents); } protected abstract String getType( ): protected abstract void execute Transaction(int cents)}class CreditCard ( 3 ) { public CreditCard(String name, String num){ (4) ;} @Override protected String getType( ){ return"CREDIT";} @Override protected void execute Transaction(int cents) { System. out. Println(cents +"paid using Credit Card. "); }} Class Bill {//包含所有购买商品的账单 private List items =new ArrayList< >( ); public void add(Item item) { items. add(item): } public intgetTotalPrice( ) {/*计算所有 item 的总价格,代码略*/} public void pay( PaymentMethod paymentMethod) {//用指定的支付方式完成支付(5) (getTotalPrice(): }}public class Paymentsystem { public void pay( ) { Bill bill =new Bill ( ); Item item1 = new Item(1234, 10); Item item2 new Item(“5678”, 40); Bill.add(item1); bill. add(item2);//将物品添加到账单中 Bill.pay(new Creditcard("LI SI”, "98765432101"))∥信用卡支付} public static void main(Stringl args) { (6) = new Paymentsystem( ); payment pay( ); }}


    答案:
    解析:
    (1)void pay(int cents)(2)implements PaymentMethod(3)extends Card(4)super(name, num)(5)paymentMethod.pay(6)Paymentsystem payment
    【解析】

    PaymentMethoc 是个接口,里面的方法在实现类当中进行具体实现,实现类是card和cash,所以第二空填implements PaymentMethoc。在图示中, PaymenuMethoc 中有pay方法,且在实现类中card也有pay方法,所以第一空填void pay( int cents)。第三空填Creditcard类与其他类的关系,可以发现它继承了Card类,所以这里填: extends Card第四空Creditcard内有构造方法,并将方法内的参数传递给父类的私有成员,填:super( name. num)第五空根据传入的paymentMetho象,进行调用pay方法,传入getTotal Price ()的值,所以这里填paymentMethod. pay利用语句 Paymentsystem paymentanew Paymentsystem ( ) 创建一个Paymentsystem类的对象,对象名为payment,然后下面开始调用pay方法。

  • 第8题:

    试题六(共 15 分)阅读下列说明和 C++代码,填补代码中的空缺,将解答填入答题纸的对应栏内。【说明】以下 C++代码实现一个简单客户关系管理系统(CrM)中通过工厂(Customerfactory)对象来创建客户(Customer)对象的功能。客户分为创建成功的客户(realCustomer)和空客户(NullCustomer)。空客户对象是当不满足特定条件时创建或获取的对象。类间关系如图6-1 所示。

    【C++代码】#include#includeusing namespace std; class Customer{protected:string name;public:(1) boll isNil()=0;(2) string getName()=0;﹜; class realCustomer (3){public:realCustomer(string name){this->name=name;﹜bool isNil(){ return false;﹜string getName(){ return name;﹜﹜; class NullCustomer (4) {public:bool isNil(){ return true;﹜string getName(){ return 〝Not Available in Customer Database〞; ﹜﹜;class Customerfactory{public:string names[3]={〝rob〞, 〝Joe〞,〝Julie〞﹜;public:Customer*getCustomer(string name){for (int i=0;i<3;i++){if (names[i].(5) ){return new realCustomer(name);﹜﹜return (6);﹜﹜; class CrM{public:void getCustomer(){Customerfactory*(7);Customer*customer1=cf->getCustomer(〝rob〞);Customer*customer2=cf->getCustomer(〝Bob〞);Customer*customer3=cf->getCustomer(〝Julie〞);Customer*customer4=cf->getCustomer(〝Laura〞); cout<<〝Customers〞<getName() <getName() <getName() <getName() <getCustomer();delete crs;return 0;﹜ /*程序输出为:CustomersrobNot Available in Customer DatabaseJulieNot Available in Customer Database*/


    答案:
    解析:
    1)virtual2)virtual3):public Customer4):public Customer5)compare(name)==06)new Null Customer()7)cf=New CustomerFactory();
    【解析】

    本题考察使用C++代码实现实际问题。在C++中,动态绑定是通过虚函数来实现的。此题中用到了虚函数,所以要在成员函数原型缺钱加一个关键字virtual。类RealCustomer和类NullCustomer是类Customer的派生类,因此3、4空都填public Customer。进行对比数据库中的人名compare(name)==0第6空与前面语句是相反的,一个是返回new RealCustomer(name),那么此处应填:new Null Customer()第7空,用工厂创建对象,cf=New CustomerFactory();

  • 第9题:

    试题五(共 15 分)阅读以下说明和 Java 程序,填补代码中的空缺,将解答填入答题纸的对应 栏内。【说明】以下 Java 代码实现一个简单的聊天室系统(ChatRoomSystem),多个用 户(User)可以向聊天室( ChatRoom)发送消息,聊天室将消息展示给所有用户。 类图如图 5-1 所示。

    【Java 代码】 class ChatRoom {
    public static void showMessage(User user, Strmg message) {System.out.println("[" + user.getName() + "] : " + message);} }classUser{private String name; public String getName() { return name;}public void setName(String name) { this.name = name;}public User(String name) { (1) =name;}public void sendMessage(String message) { (2) (this, message);}}public class Chat:RoomSystem { public void startup() {
    User zhang= new User("John");User li =new User("Leo"); zhang.sendMessage("Hi! Leo! "); 1i.sendMessage("Hi! John!"); } public void join(User user) { (3) ("Hello Everyone! I am" + user.getName()); }public static void main(String[] args) { ChatRoomSystem crs= (4) ; Crs.startup();Crs.join( (5) )(“Wayne”));}}/*程序运行结果: [John]:Hi! Leol [Leo]:Hi! John![Wayne】:Hello Everyone!Iam Wayne*/


    答案:
    解析:
    1、this.name
    2、ChatRoom.showMessage
    3、user.sendMessage
    4、new ChatRoomSystem()
    5、new User

  • 第10题:

    阅读下列说明和 Java 代码,将应填入(n)处的字句写在答题纸的对应栏内。
    【说明】
    生成器( Builder)模式的意图是将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示。图 6-1 所示为其类图。



    阅读下列说明和C++代码,将应填入(n)处的字句写在答题纸的对应栏内。

    【说明】

    ???? 生成器(Builder)模式的意图是将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示。图5-1所示为其类图。

    ?

    【C++代码】

    #include

    #include

    using namespace std;
    class Product {
    private:?
    string partA, partB;
    public:?
    Product() {?? }? ?
    void setPartA(const string& s) { PartA = s;}
    ???? void setPartB(const string& s) { PartB
    = s;}? ?
    //? 其余代码省略
    };
    class Builder {
    public:? ? ??
    (1)??
    ;?
    virtual void buildPartB()=0;? ? ?
    (2)??
    ;
    };
    class ConcreteBuilder1 : public Builder {
    private:?
    Product*?? product;
    public:
    ConcreteBuilder1() {product = new Product();???? }
    void buildPartA() {????? (3)???? ("Component
    A"); }?
    void buildPartB() {????? (4)???? ("Component
    B"); }??
    Product* getResult() { return product; }
    //? 其余代码省略
    };
    class ConcreteBuilder2 : public Builder {? ??? ? ? ?
    /*??? 代码省略??? */
    };
    class Director {
    private:? ??
    Builder* builder;
    public:??
    Director(Builder* pBuilder) { builder= pBuilder;}? ??
    void construct() {
    ????????????????? (5)???? ;
    ?????????????? //? 其余代码省略? ?
    }??
    //? 其余代码省略
    };
    int main() {? ? ??
    Director* director1 = new Director(new ConcreteBuilder1());? ?
    director1->construct();? ? ??
    delete director1;? ? ?
    return 0;
    【Java代码】
    import jav(6)A.util.*;
    class Product {? ? ? ?
    private String partA;? ? ? ?
    private String partB;? ? ? ??
    public Product() {}? ? ??
    public void setPartA(String s) { partA = s; }? ? ? ?
    public void setPartB(String s) { partB = s; }
    }
    interface Builder {? ?
    public?????? (1)???? ;? ??
    public void buildPartB();? ? ??
    public?????? (2)???? ;
    }
    class ConcreteBuilder1 implements Builder {? ? ? ?
    private Product product;? ? ? ?
    public ConcreteBuilder1() { product = new Product();?? }? ? ? ??
    public void buildPartA() {????????
    (3)??
    ("Component A"); }
    public void buildPartB() {???? ????(4)?? ("Component B"); }? ? ??
    public Product getResult() { return product;}
    }
    class ConcreteBuilder2 implements Builder {?? ? ? ? ?
    //? 代码省略
    }
    class Director {? ? ? ?
    private Builder builder;? ? ? ?
    public Director(Builder builder) {this.builder = builder; }
    public void construct() {
    ? ? ? ? ? ? ? ? ? (5)???? ;
    ? ? ? ? ? ? ? //? 代码省略? ? ??
    }
    }
    class Test {? ? ??
    public static void main(String[] args) {
    ???????????????? Director director1 = new
    Director(new ConcreteBuilder1());
    ???????????????? director1.construct();? ? ? ??
    }


    答案:
    解析:
    (1)void buildPart A()
    (2) Product getResult()
    (3)product.setPartA
    (4)product.setPartB
    (5)builder.buildPartA();
    builder.buildPartB();
    Product p=builder.getResult();

  • 第11题:

    现有:  class HorseRadish  {      //insert code here  protected HorseRadish (int x)    {      System.out.println ("bok choy");      }      }  class Wasabi extends HorseRadish  {  public static void main (String  []  args){    Wasabi w- new Wasabi();     }     }  分别插入到第2行,哪两项允许代码编译并产生”bok choy”输出结果()

    • A、 protected HorseRadish()  {this (42);}
    • B、  protected HorseRadish()  {}
    • C、  //just a comment
    • D、  protected  HorseRadish()  {  new HorseRadish (42);}

    正确答案:A,D

  • 第12题:

    单选题
    现有:  1. abstract class Color  {  2.protected abstract  String getRGB();     3.  }     4.  5. public class Blue extends Color  {     6.    //insert code here      7.  }  和四个声明:  public String getRGB()  {  return "blue";  }      String getRGB()  {  return  "blue";  )  private  String getRGB()  {  return  "blue";  }      protected String getRGB()  {  return "blue";  )      分别插入到第6行,有几个可以通过编译?()
    A

      0

    B

      1

    C

      2

    D

      3


    正确答案: B
    解析: 暂无解析

  • 第13题:

    阅读下列说明和c++代码,将应填入 (n) 处的字句写在答题纸的对应栏内。

    【说明】

    现欲构造一文件/目录树,采用组合(Composite)设计模式来设计,得到的类图如6—7所示:

    【c++代码】

    include<1ist>

    include

    include

    using namespace std;

    class AbstractFile{

    protected:

    string name;//文件或目录名称

    public:

    void printName(){cout<*getChildren()=0; //获得一个目录的子目录或文件

    };

    class File:public AbstractFile{

    public:

    File(string name){ (1) =name;)

    void addChild(AbstractFile*file){return ;)

    void removeChiid(AbstractFile*file){return;}(2) getChildren(){return ( 3 ) ;}

    };

    class Folder:public AbstractFile{

    private:

    listchildList; //存储子目录或文件

    public:

    Folder(string name){ (4) =name;}

    void addChild(AbstractFile*file){childList.push back(file);}

    void removeChiid(AbstractFile*file)(chiidList.remove(file);}

    list*getChildren(){return (5) ;)

    };

    voidmain(){

    //构造一个树形的文件/目录结构

    AbstractFile*rootFolder=new Folder(“C:\\”);

    AbstractFile*compositeFolder=flew Folder(”composite”);

    AbstractFile*windowsFolder=new Folder(”windows”);

    AbstractFile*file=new File(”TestComposite.java”);

    rootFolder->addChild(compositeFolder);

    rootFolder->addChild (windowsFolder);

    compositeFolder->addChiid(file);

    )


    正确答案:(1)this一>name(2)list<AbstractFile*>*(3)NULL(4)this->name(5)&childList
    (1)this一>name(2)list<AbstractFile*>*(3)NULL(4)this->name(5)&childList 解析:Composite模式定义:将对象以树型结构组织起来,以达成“部分一整体”的层次结构,使得客户端对单个对象和组合对象的使用具有一致性。Composite比较容易理解,想到Composite就应该想到树形结构图。组合体内这些对象都有共同接口,当组合体一个对象的方法被调用执行时,Composite将遍历(Iterator)整个树形结构,寻找同样包含这个方法的对象并实现调用执行。AbstractFile为一个抽象文件类,其作用主要是实现对文件或者文件夹的抽象。文件类File继承自AbstractFile。File(stringname)为File类的一个属性,用于获取文件名称。Addchild方法用来给一个目录增加子目录或文件。Removechild方法用于删除一个目录的子目录或文件。Getchildren方法用于获取一个目录或文件,所以返回值类型应该是一个列表形式的AbstractFile,但文件本身不包括子目录,故返回NULL。Fold类表示一个文件夹,属性Fold.er用于获取文件夹名称,Getchildren方法返回值应为List型的AbstractFile对象指针。

  • 第14题:

    阅读以下说明和JAVA 2代码,将应填入(n)处的字句写在对应栏内。

    [说明]

    以下程序为类类型的变量应用实例,通过异常处理检验了类CCircle的变量的合法性,即参数半径应为非负值。仔细阅读代码和相关注释,将程序补充完整。

    [JAVA代码]

    //定义自己的异常类

    class CCircleException extends Exception

    {

    }

    // 定义类 CCircle

    class CCircle

    {

    private double radius;

    public void setRadius ( double r ) (1)

    {

    if ( r<0 ) {

    (2)

    }

    else

    (3)

    }

    Public void show ( ) {

    System. out. println ( "area="+3.14*radius*radius );

    }

    }

    public class ciusample

    {

    public static void main ( String args[] )

    {

    CCircle cir=new CCircle( );

    (4) {

    cir. setRadius ( -2.0 )

    }

    (5)

    {

    System. out. println ( e+" throwed" ) ;

    }

    cir. show( ) ;

    }

    }


    正确答案:(1)throws CCircleException (2)throw new CCircleException(); //抛出异常 (3)radius=r; (4)try (5)catch(CCircleException e) //捕捉由setRadius()抛出的异常
    (1)throws CCircleException (2)throw new CCircleException(); //抛出异常 (3)radius=r; (4)try (5)catch(CCircleException e) //捕捉由setRadius()抛出的异常 解析:本题主要考查JAVA语言中Class类型的变量应用。本段代码中对于类Ccircle的半径变量进行合法性检验,如果圆Ccircle的半径为负值,则抛出异常处理。

  • 第15题:

    阅读以下说明和 Java程序,填补代码中的空缺,将解答填入答题纸的对应栏内。 【说明】 以下Java代码实现一个简单客户关系管理系统(CRM)中通过工厂(CustomerFactory )对象来创建客户(Customer)对象的功能。客户分为创建成功的客户(RealCustomer)和空客户 (NullCustomer)。空客户对象是当不满足特定条件时创建或获取的对象。类间关系如图 5-1 所示。图5-1 类图

    【Java代码】 Abstract class Customer﹛ Protected String name; ( 1 )boolean isNil(); ( 2 )String getName(); ﹜ Class RealCustomer ( 3 )Customer{ Public RealCustomer(String name){ this.name=name; } Public String getName(){ return name ; } Public boolean is Nil() { return false; } ﹜ Class NullCustomer( 4 )Customer﹛ Public String getName()﹛ return "Not Available in Customer Database"; ﹜ Public boolean isNil() ﹛ return true; ﹜ ﹜ class Customerfactory { public String[] names = {"Rob","Joe","Julie"}; public Customer getCustomer(String name) { for (int i = 0; i < names.length;i++) { if (names[i].( 5 ))﹛ return new RealCustomer(name); ﹜ ﹜ return ( 6 ); ﹜ ﹜ Public class CrM﹛ Public viod get Customer()﹛ Customerfactory( 7 ); Customer customer1-cf.getCustomer("Rob"); Customer customer2=cf.getCustomer("Bob"); Customer customer3= cf.getCustomer("Julie"); Customer customer4= cf.getCustomer("Laura"); System.out.println("customers”) System.out.println(customer1.getName()); System.out.println(customer2getName()); System.out.println(customer3.getName()); System.out.println(customer4.getName()); ﹜ Public static viod main (String[]arge)﹛ CRM crm =new CRM(); Crm.getCustomer(); ﹜ ﹜ /*程序输出为: Customers rob Not Available in Customer Database Julie Not Available in Customer Database */


    正确答案:1)public abstract
    2) public abstract
    3)extends
    4)extends
    5)equals(name)
    6)new Null Customer()
    7) cf=New CustomerFactory();

  • 第16题:

    阅读下列说明和 Java代码,将应填入 (n) 处的字句写在答题纸的对应栏内。 【说明】 某快餐厅主要制作并出售儿童套餐,一般包括主餐(各类比萨)、饮料和玩具,其餐品种类可能不同,但其制作过程相同。前台服务员 (Waiter) 调度厨师制作套餐。现采用生成器 (Builder) 模式实现制作过程,得到如图 6-1 所示的类图。【Java代码】 class Pizza { private String parts; public void setParts(String parts) { this.parts = parts; } public String toString() { return this.parts; } } abstract class PizzaBuilder { protected Pizza pizza; public Pizza getPizza() { return pizza; } public void createNewPizza() { pizza = new Pizza(); } public (1) ; } class HawaiianPizzaBuilder extends PizzaBuilder { public void buildParts() { pizza.setParts("cross + mild + ham&pineapp1e”}; } class SpicyPizzaBuilder extends PizzaBuilder { public void buildParts() { pizza.setParts("pan baked + hot + pepperoni&salami"); } } class Waiter { private PizzaBuilder pizzaBuilder; public void setPizzaBuilder(PizzaBuilder pizzaBuilder) { /*设置构建器*/ ( 2 ) ; } public Pizza getPizza(){ return pizzaBuilder.getPizza(); } public void construct() { /*构建*/ pizzaBuilder.createNewPizza(); ( 3 ) ; } } Class FastFoodOrdering { public static viod mainSting[]args) { Waiter waiter = new Waiter(); PizzaBuilder hawaiian_pizzabuilder = new HawaiianPizzaBuilder(); ( 4 ) ; ( 5 ) ; System.out.println("pizza: " + waiter.getPizza()); } } 程序的输出结果为: Pizza:cross + mild + ham&pineapple


    正确答案:(1)abstract void buildParts();
    (2)this.pizzaBuilder=pizzaBuilder
    (3)pizzaBuilder.buildParts()
    (4)waiter.setPizzaBuilder(hawaiian_pizzabuilder)
    (5)waiter.construct()

  • 第17题:

    阅读以下说明和Java代码,将应填入(n)处的字句写在对应栏内。

    [说明]

    在一些大型系统中,大多数的功能在初始化时要花费很多时间,如果在启动的时候,所有功能(连不用的功能)都要全面初始化的话,会连带影响到应用软件要花很多时间才能启动。因此常将程序设计成到了实际要使用某种功能的阶段才初始化该功能。

    以下示例展示了Proxy(代理)模式,PrinterProxy类执行一些比较“轻”的方法——设置名称和取得名称,需要真正执行“重”的方法——真正打印——时才初始Print类。图6-1显示了各个类间的关系。

    [图6-1]

    [Java代码]

    //Printable.Java

    publiC (1) Printable{

    public abstract void setPrinterName(String name);

    public abstract String getprinterName();

    public abstract void print(String string);

    }

    //Printer.Java

    public class Printer implements Printable{

    private String name;

    public Printer(){

    System.out.println("正在产生Printer的对象实例");

    }

    public Printer(String name){

    this.name=name;

    heavyJob("正在产生Printer的对象实例("+name+")");

    public void setPrinterName(String name){

    this.name=name;

    public String getPrinterName(){

    return name;

    public void print(String string){

    System.out.println("===" +name+" ====");

    System.out.println(string);

    }

    }

    //PrinterProxy.Java

    public class PrinterProxy (2) Printable{

    private String name;

    private Printer real;

    public PrinterProxy(){}

    public PrinterProxy(String name){

    this.name=name;

    }

    public gynchronized void setPrinterName(String name){

    if( (3) ){

    real.setPrinterName(name);

    }

    this.name=name;

    }

    public String getprinterName(){

    return name;

    }

    public void print(String string){

    (4);

    real.print(string);

    }

    private synchronized void realize(){//产生真正的Printer对象

    if(real==null){

    real=(5);

    }

    }

    }

    (1)


    正确答案:interface
    interface

  • 第18题:

    试题五(共 15 分)阅读以下说明和 Java 程序,填补代码中的空缺,将解答填入答题纸的对应栏内。【说明】以下 Jave 代码实现一个简单客户关系管理系统(CrM) 中通过工厂 (Customerrfactory )对象来创建客户(Customer) 对象的功能。客户分为创建成功的客户 (realCustomer) 和空客户(NullCustomer) 。空客户对象是当不满足特定条件时创建或获取的对象。类间关系如图 5-1 所示。【Java 代码】Abstract class Customer﹛Protected String name;()boolean isNil()()String getName();﹜ Class realCustomer ()Customer﹛Public realCustomer(String name )﹛ return false; ﹜﹜ Class NullCustomer()Customer﹛Public String getName()﹛ return ″Not Available in Customer Database″; ﹜Public boolean isNil()﹛ return true; ﹜﹜ class Customerfactory {public String[] names = {"rob","Joe","Julie"};public Customer getCustomer(String name) {for (int i = 0; i < names.length;i++) {if (names[i].())﹛return new realCusωmer(name);﹜﹜return ()﹜﹜ Public class CrM﹛Public viod get Customer()﹛Customerfactory()Customer customer1-cf.getCustomer(″rob″);Customer customer2=cf.getCustomer(″rob″);Customer customer3= cf.getCustomer(″Julie″);Customer customer4= cf.getCustomer(″Laura″);System.out.println(″customer1.getName());System.out.println(″customer2getName());System.out.println(″customer3.getName());System.out.println(″customer4.getName());﹜ Public static viod main (String[]arge)﹛CrM crm =new CrM();Crm,getCustomer();﹜﹜/*程序输出为:CustomerrobNot Available in Customer DatabaseJulieNot Available in Customer Datable*/int main()﹛CrM*crs=newCrM();Crs->getCustomer();Crs->getCustomer();Delete crs;return();﹜/*程序输出为:CustomerrobNot Available ini Customer DatabaseJulieNot Available in Customer Database


    答案:
    解析:
    1)public abstract2) public abstract3)extends4)extends5)equals(name)6)new Null Customer()7) cf=New CustomerFactory();
    【解析】

    本题考察Java程序设计客户关系管理系统。1)public abstract 定义可访问方法2) public abstract3)extends 继承Customer类4)extends5)equals(name) 判断名字是否在数组集合内6)new Null Customer() 当不满足条件时创建一个空对象7) cf=New CustomerFactory(); 实例化对象cf

  • 第19题:

    阅读下列说明和Java代码,将应填入(n)处的字句写在答题纸的对应栏内。 【说明】 某发票(lnvoice)由抬头(Head)部分、正文部分和脚注(Foot)部分构成。现采用装饰(Decorator)模式实现打印发票的功能,得到如图6-1所示的类图。

    【java代码】 class invoice{ public void printInvoice(){: System.out.println("This is the content of the invoice!"); } } class Decorator:extends Invoice{ protected Invoice ticket; public Decorator(lnvoice t){ ticket=t; } public void printinvoice(){ if(ticket!=NULL) (1); } } class FootDecorator extends Decorator{ public FootDecorator(lnvoice t){ super(t); } public void printinvoice(){ Systent.out.println("This is the header of the invoice!"); (2); } } class FootDecorator extends Decorator{ public FootDecorator(invoice t):{ super(t); } public void printlnvoice(){ (3); Systent.out.println("This is the header of the invoice!"); } } Class test{ public static void main(string[]args){ Invoice t=new invioce(); Invoice ticket; Ticket=(4); Ticket.Printinvoice(); Systent.out.println(“--------------“) Ticket=(5); Ticket.Printinvoice(); } } 程序的输出结果为: This is the header of the invoice! This is the content of the invoice! This is the footnote of the invoice! ---------------------------- This is the header of the invoice! This is the footnote of the invoice!


    答案:
    解析:
    (1) ticket.printInvoice() (2) ticket.printInvoice() (3) ticket.printInvoice() (4) new FootDecorator(new HeadDecorator(t)) (5) new FootDecorator(new HeadDecorator(new Decorator(null)))
    【解析】

    试题分析
    本题考查的是面向对象程序设计和设计模式。本题涉及的设计模式是装饰模式。装饰模式(Decorator) :动态地给一个对象添加一些额外的职责。它提供了用子类打展功能的一个灵活的替代,比派生一个子类更加灵活。
    对于程序填空可以参照代码上下文、题干说明和设计模式综合考虑。
    对于第(1) 空,是对printInvoice方法的具体调用,在Decorator是 装饰类,继承了Invoice发票类。此处需要填写的是printInvoice方法的方法体,根据Decorator类的上下文,已定义ticket对象,所以此处调用printinvoice方法的是ticket,第(1) 空填写ticket printlnvoice()。
    对于第(2) (3) 空,根据类图可知,分别是HeadDecorator抬头 类、FootDecorator脚注类调用printInvoice方法的方法体,由于在这两个类中并没有定义属性,只有借助其超类的构造函数,所以这两个地方调用printlnvoice方法的是它们的超类,即(2) (3) 填写的是super.printInvoice()。
    对于第(4) (5) 空,考查的是对装饰模式的调用,都是main函数中实例化的过程,根据输出结果可以看到,第(4)空实例化ticket对象,可以输出抬头、内容、脚注3个部分, 因此需要调用三者的printInvoice()方法, 前面已经实例化了一个Invoice对象t,可以利用给子类实例化,因此第(4) 空填写new HeadDecorator(new FootDecorator());而第(5)空没有输出具体内容,只有抬头和脚注部分,可以看到这里的Invoice对象应该是空,所以第(5) 空填写new HeadDecorator(new FootDecorator(nl)。

  • 第20题:

    阅读下列说明和Java代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】某软件公司欲开发一款汽车竞速类游戏,需要模拟长轮胎和短轮胎急刹车时在路面上留 下的不同痕迹,并考虑后续能模拟更多种轮胎急刹车时的痕迹。现采用策略(Strategy)设计模式来实现该需求,所设计的类图如图 5-1 所示。

    【Java代码】import java.util.*; interface BrakeBehavior{public (1) ;/*其余代码省略*/}class LongWheelBrake implements BrakeBehavior{public void stop(){System.out.println("模拟长轮胎刹车痕迹! ");}/*其余代码省略*/}class ShortWheelBrake implements BrakeBehavior {public void stop(){System.out.println("模拟短轮胎刹车痕迹! ");}/*其余代码省略 */}abstract class Car{protected (2) wheel;public void brake(){ (3) ;}/*其余代码省略*/}class ShortWheelCar extends Car {public ShortWheelCar(BrakeBehavior behavior){(4) ; } /*其余代码省略*/}class StrategyTest{public static void main(String[]args){BrakeBehaviorbrake =new ShortWheelBrake();ShortWheelCar car1= new ShortWheelCar(brake);car1. (5) ;}}


    答案:
    解析:
    1. void stop()2. BrakeBehavior3. wheel.stop()4. wheel=behavior5. brake()

  • 第21题:

    阅读下列说明和java代码,将应填入 (n) 处的字句写在答题纸的对应栏内。
    【说明】
    某发票(lnvoice)由抬头(Head)部分、正文部分和脚注(Foot)部分构成。现采用装饰(Decorator)模式实现打印发票的功能,得到如图6-1所示的类图。

    【java代码】
    class invoice{
    public void printInvoice( ){

    System.out.println ( "This is the content of the invoice!");
    }
    }
    class Decorator extends Invoice {

    protected Invoice ticket;

    public Decorator(lnvoice t){

    ticket = t;
    }
    public
    void printInvoice( ){

    if(ticket != null)
    (1) ;

    }
    }
    class HeadDecorator extends Decorator{

    public HeadDecorator(lnvoice t){

    super(t);
    }

    public void printInvoice ( ){

    Systent.out.println( "This is the header of the invoice! ");
    (2) ;
    }
    }
    class FootDecorator extends Decorator {

    public FootDecorator(Invoice t){

    super(t);
    }

    public void printlnvoice( ){

    ( 3) ;

    Systent.out.println( "This is the footnote of the invoice! ");
    }
    }
    Class test {

    public static void main(String[] args){

    Invoice t =new Invioce( );

    Invoice ticket;

    ticket= (4) ;

    ticket.printInvoice( );

    Systent.out.println(“------------------“);

    ticket= (5) ;

    ticket.printInvoice( );
    }
    }
    程序的输出结果为:

    This is the header of the invoice!

    This is the content of the invoice!

    This is the footnote of the invoice!

    ----------------------------

    This is the header of the invoice!

    This is the footnote of the invoice!


    答案:
    解析:
    (1) ticket.printInvoice()
    (2) ticket.printInvoice()

    (3) ticket.printInvoice()

    (4) new FootDecorator(new

  • 第22题:

    现有:   1.  class HorseRadish {   2.    // insert code here   3.    protected HorseRadish(int x) {    4.      System.out.println("bok choy");  5.    }  6.  }   7.  class Wasabi extends HorseRadish {   8.    public static void main(String [] args) {   9.      Wasabi w = new Wasabi();  10.   }    11. }   分别插入到第 2 行,哪两项允许代码编译并产生"bok choy" 输出结果?() 

    • A、 // just a comment
    • B、 protected HorseRadish() { }
    • C、 protected HorseRadish() { this(42);}
    • D、 protected  HorseRadish() { new HorseRadish (42);}

    正确答案:C,D

  • 第23题:

    现有:  1. abstract class Color  {  2.protected abstract  String getRGB();     3.  }     4.  5. public class Blue extends Color  {     6.    //insert code here      7.  }  和四个声明:  public String getRGB()  {  return "blue";  }      String getRGB()  {  return  "blue";  )  private  String getRGB()  {  return  "blue";  }      protected String getRGB()  {  return "blue";  )      分别插入到第6行,有几个可以通过编译?()    

    • A、  0
    • B、  1
    • C、  2
    • D、  3

    正确答案:C