单选题现有  class Beverage {  Beverage ()  {  System.out.print ("beverage ");  }        }  class Beer extends Beverage {  public static void main{string [] args) {        Beer b = new Beer (14) ;       }  public int Beer(int x) {       this () ;  System.out.pr

题目
单选题
现有  class Beverage {  Beverage ()  {  System.out.print ("beverage ");  }        }  class Beer extends Beverage {  public static void main{string [] args) {        Beer b = new Beer (14) ;       }  public int Beer(int x) {       this () ;  System.out.print ("beerl") ;      }  public Beer() { System.out.print("beer2 "); }     }  结果是什么?()
A

beerl beverage

B

beer2 beverage

C

beverage beer2 beerl

D

编译失败


相似考题

4.阅读下列说明与相关类图,填空并回答问题。【说明】装饰者模式动态地给一个对象添加一些额外的职责,就扩展功能而言,该模式比生成子类方式更加灵活。装饰模式的提出有助于解决滥用继承的问题。例如,一个名叫星巴兹(Starbuzz)的咖啡连锁店提供多种多样的咖啡,最朴素的设计就是采用继承,即设计一个饮料抽象基类Beverage,让不同种类的咖啡HouseBlend、 Decaf、Espresso、DarkRoast继承Beverage类,如图13-23所示。Beverage类的cost()方法是抽象方法,每个子类的cost()方法实现即返回具体咖啡种类的价钱,Beverage类的 description实例变量由每个子类设置,用来描述该类饮料,Beverage类的getDescription()方法用来返回此描述。客户在点咖啡时还可以要求添加各种各样的调料(Condiment),加入的调料不同所收取的费用也是不同的,让各种加了调料的不同咖啡都继承基类Beverage,当咖啡种类和调料种类很多时,组合种类的数量就会急剧增长,就会发生“类数量爆炸”现象,如图13-24所示。显然,采用这种设计方式会使得代码的维护变得十分困难,可以采用装饰者模式来解决这个问题。软件设计师蝴蝶飞根据装饰者模式的思想设计了如图13-25所示的类图。在图13-25中,将各种调料Milk、Mocha、Soy、Whip作为装饰者来装饰House- Blend、Decal、Espresso、DarkRoast等各种咖啡。下面的Java程序(代码13-6)对应其具体实现。【代码13-6】import java.io.* ;abstract class Beverage{String description="Unknown Beverage";public String getDescription(){return description;}public (1) double cost();}abstract class CondimentDecorator (2) Beverage {public abstract Strmg getDescription();}class Decafextends Beverage {public Decaf(){description="Decaf Coffee";}public double cost(){return 1.05;}}class Espresso extends Beverage {public Espresso() {description="Espresso";}public double cost(){return 1.99;}}class HouseBlend extends Beverage{public HouseBlend(){description="House Blend Coffee";}public double cost(){return.89;}}class DarkRoast extends Beverage{public DarkRoast(){description="Dark Roast Coffee";}public double cost(){return.99;}}class Mocha extends CondtmentDecorator{Beverage (3);public Mocha(Beverage beverage){this.beverage=beverage;}public String getDescription(){return beverage.getDescription()+", Mocha";}public double cost(){return.20+beverage.cost();}}Class Soy extends CondimentDecorator{Beverage beverage;public Soy(Beverage beverage) {this.beverage=beverage;}public Strillg getDescription(){

更多“现有  class Beverage {  Beverage ()  {  System.out.print ("bev”相关问题
  • 第1题:

    禁止游客随身携带( )

    A.BIG SCISSORS

    B.YOGURT

    C.TIN

    D.AERATED BEVERAGE


    正确答案:A

  • 第2题:

    试题六(共15分)

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

    【说明】

    某咖啡店当卖咖啡时,可以根据顾客的要求在其中加入各种配料,咖啡店会根据所加入的配料来计算费用。咖啡店所供应的咖啡及配料的种类和价格如下表所示。

    【Java代码】

    import java.util.*;

    (1) class Beverage { //饮料

    String description = "Unknown Beverage";

    public (2) (){return description;}

    public (3) ;

    }

    abstract class CondimentDecorator extends Beverage { //配料

    (4) ;

    }

    class Espresso extends Beverage { //蒸馏咖啡

    private final int ESPRESSO_PRICE = 25;

    public Espresso() { description="Espresso"; }

    public int cost() { return ESPRESSO_PRICE; }

    }

    class DarkRoast extends Beverage { //深度烘焙咖啡

    private finalint DARKROAST_PRICE = 20;

    public DarkRoast() { description = "DarkRoast"; }

    public int cost(){ rcturn DARKROAST PRICE; }

    }

    class Mocha extends CondimentDecorator { //摩卡

    private final int MOCHA_PRICE = 10;

    public Mocha(Beverage beverage) {

    this.beverage = beverage;

    }

    public String getDescription() {

    return beverage.getDescription0 + ", Mocha";

    }

    public int cost() {

    return MOCHA_PRICE + beverage.cost();

    }

    }

    class Whip extends CondimentDecorator { //奶泡

    private finalint WHIP_PRICE = 8;

    public Whip(Beverage beverage) { this.beverage = beverage; }

    public String getDescription() {

    return beverage.getDescription()+", Whip";

    }

    public int cost() { return WHIP_PRICE + beverage.cost(); }

    }

    public class Coffee {

    public static void main(String args[]) {

    Beverage beverage = new DarkRoast();

    beverage=new Mocha( 5 );

    beverage=new Whip ( 6 );

    System.out.println(beverage.getDescription() +"¥" +beverage.cost());

    }

    }

    编译运行上述程序,其输出结果为:

    DarkRoast, Mocha, Whip ¥38


    正确答案:
    (1) abstract
    (2) String getDescription
    (3) abstract int cost()
    ( 4) Beverage beverage
    (5) beverage
    (6) beverage

  • 第3题:

    Water,Coffee,Wine和OrangeJuice都属于Beverage


    正确答案:错误

  • 第4题:

    果汁饮料(fruit juice beverage)


    正确答案: 是指在果汁(浆)或浓缩果汁中加入水、食糖(或)甜味剂、酸味剂等调制而成的饮料,可加入柑橘类的囊胞(或其他水果经切细的果肉)等果粒。果汁含量≥10%(质量分数)。

  • 第5题:

    class Beverage {   Beverage() { System.out.print("beverage "); }   }   class Beer extends Beverage {   public static void main(String [] args) {   Beer b = new Beer(14);   }   public int Beer(int x) {   this();   System.out.print("beer1 ");   }   public Beer() { System.out.print("beer2 "); }  }   结果是什么?()  

    • A、beer1 beverage
    • B、beer2 beverage
    • C、beverage beer1
    • D、编译失败

    正确答案:D

  • 第6题:

    现有  class Beverage {  Beverage ()  {  System.out.print ("beverage ");  }        }  class Beer extends Beverage {  public static void main{string [] args) {        Beer b = new Beer (14) ;       }  public int Beer(int x) {       this () ;  System.out.print ("beerl") ;      }  public Beer() { System.out.print("beer2 "); }     }  结果是什么?() 

    • A、beerl beverage
    • B、beer2 beverage
    • C、beverage beer2 beerl
    • D、编译失败

    正确答案:D

  • 第7题:

    单选题
    What regulation was issued by New York State concerning beverage containers?
    A

    Beverage companies should be responsible for collecting and reusing discarded plastic soda bottles.

    B

    Throwaways should be collected by the state for recycling.

    C

    A fee should be charged on used containers for recycling.

    D

    Consumers had to pay for beverage containers and could get their money back on returning them.


    正确答案: A
    解析:
    细节题。D项“消费者退还瓶子时还可以重新得到预付的瓶子钱”与首段首句意思相符。

  • 第8题:

    单选题
    The key problem in dealing with returned plastic beverage containers is _____.
    A

    to sell them at a profitable price

    B

    how to turn them into useful things

    C

    how to reduce their recycling costs

    D

    to lower the prices for used materials


    正确答案: B
    解析:
    细节推断题。第二段提到,直到现有的经济的废物处理方法给了它第二次生命的价值,即让它变成有用的东西,否则它就会一直是垃圾。这与B项意思相同,故B项正确。

  • 第9题:

    单选题
    Which of the following is NOT used by the author to stop the child’s crying at night?
    A

    Leaving the baby crying alone in a room unattended.

    B

    Letting the baby listen to the radio for the nursery.

    C

    Feeding the baby with some warm milk and beverage.

    D

    Allowing the child to sleep in an absence of noise.


    正确答案: C
    解析:
    事实细节题。文章第五段介绍了这位母亲用了三种方法哄孩子,但没有D“允许孩子在无噪音的环境中睡觉”,所以选D。

  • 第10题:

    单选题
    现有:  class Number{  public static void main(String  []  aras)  {      try  {  System.out.print (Integer.parselnt ("forty"));      } catch (RuntimeException r)  {      System.out.print ("runtime");  } catch  (NumberFormatException e)  {      system..ut.print("number");      }      }      }  结果是什么?()
    A

    number

    B

    runtime

    C

    forty number

    D

    编译失败


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

  • 第11题:

    单选题
    现有:      class Cat  {      Cat (int c)  {System.out.print {"cat"+c+" ");  }      }      class SubCat extends Cat  {      SubCat (int c){super (5); System.out.print ("cable");}      SubCat()  {  this (4);  }      public static void main (String  []  args)  {      SubCat s= new SubCat();      }      }     结果为:()
    A

     cat5

    B

     cable

    C

     cat5 cable

    D

     cable cat5


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

  • 第12题:

    单选题
    现有:  class Output  {  public static void main (String[]  args)    {      int i=5:  System.out.print( "4"+i+"");      System.out.print (i+5+"7");     System.out.println  (i+"8");      }      }      结果为:()
    A

      99722

    B

      955758

    C

      4510758

    D

      459722


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

  • 第13题:

    试题五(共15分)

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

    【说明】

    某咖啡店当卖咖啡时,可以根据顾客的要求在其中加入各种配料,咖啡店会根据所加入的配料来计算费用。咖啡店所供应的咖啡及配料的种类和价格如下表所示。

    【C++代码】

    include <iostream>

    include <string>

    using namespace std;

    const int ESPRESSO_PRICE = 25;

    const int DRAKROAST_PRICE = 20;

    const int MOCHA_PRICE = 10;

    const int WHIP_PRICE = 8;

    class Beverage { //饮料

    (1) :string description;

    public:

    (2) (){ return description; }

    (3) ;

    };

    class CondimentDecorator : public Beverage { //配料

    protected:

    (4) ;

    };

    class Espresso : public Beverage { //蒸馏咖啡

    public:

    Espresso () {description="Espresso"; }

    int cost(){return ESPRESSO_PRICE; }

    };

    class DarkRoast : public Beverage { //深度烘焙咖啡

    public:

    DarkRoast(){ description = "DardRoast"; }

    int cost(){ return DRAKROAST_PRICE; }

    };

    class Mocha : public CondimentDecorator { //摩卡

    public:

    Mocha(Beverage*beverage){ this->beverage=beverage; }

    string getDescription(){ return beverage->getDescription()+",Mocha"; }

    int cost(){ return MOCHA_PRICE+beverage->cost(); }

    };

    class Whip :public CondimentDecorator { //奶泡

    public:

    Whip(Beverage*beverage) { this->beverage=beverage; }

    string getDescription() {return beverage->getDescription()+",Whip"; }

    int cost() { return WHIP_PRICE+beverage->cost(); }

    };

    int main() {

    Beverage* beverage = new DarkRoast();

    beverage=new Mocha( (5) );

    beverage=new Whip( (6) );

    cout<<beverage->getDescription()<<"¥"<<beverage->cost() endl;

    return 0;

    }

    编译运行上述程序,其输出结果为:

    DarkRoast, Mocha, Whip ¥38


    正确答案:
    (1) protected
    (2) virtual string getDescription
    (3) virtual int cost()=0
    (4) Beverage*beverage
    (5) beverage
    (6) beverage

  • 第14题:

    class One {  public One() { System.out.print(1); }  }  class Two extends One {  public Two() { System.out.print(2); }  }  class Three extends Two {  public Three() { System.out.print(3); }  }  public class Numbers{  public static void main( String[] argv) { new Three(); }  }  What is the result when this code is executed?() 

    • A、 1
    • B、 3
    • C、 123
    • D、 321
    • E、 The code rims with no output.

    正确答案:C

  • 第15题:

    英译中:We provide our customers with a variety of services such as currency exchange, food and beverage, laundry, mail, etc.


    正确答案:我们向顾客提供货币兑换、餐饮、洗衣、函件等多项服务。

  • 第16题:

    现有:  class Cat {  Cat(int c) { System.out.print("cat" + c + " "); }  }  class SubCat extends Cat {  SubCat(int c) { super(5); System.out.print("cable "); }  SubCat() { this(4); }  public static void main(String [] args) {  SubCat s = new SubCat();  }  } 结果为:() 

    • A、cat5
    • B、cable
    • C、cable cat5
    • D、cat5 cable

    正确答案:D

  • 第17题:

    public class Pet{     private String name;     public Pet(){  System.out.print(1);    }  public Pet(String name){        System.out.print(2);    } }  public class Dog extends Pet{     public Dog(){  System.out.print(4);    }  public Dog(String name){        this();  System.out.print(3);    } }  执行new Dog(“棕熊”);后程序输出是哪项?()  

    • A、 143
    • B、 423
    • C、 243
    • D、 1134

    正确答案:A

  • 第18题:

    现有:  class Output  {  public static void main (String[]  args)    {      int i=5:  System.out.print( "4"+i+"");      System.out.print (i+5+"7");     System.out.println  (i+"8");      }      }      结果为:()     

    • A、  99722
    • B、  955758
    • C、  4510758
    • D、  459722

    正确答案:C

  • 第19题:

    单选题
    class Beverage {   Beverage() { System.out.print("beverage "); }   }   class Beer extends Beverage {   public static void main(String [] args) {   Beer b = new Beer(14);   }   public int Beer(int x) {   this();   System.out.print("beer1 ");   }   public Beer() { System.out.print("beer2 "); }  }   结果是什么?()
    A

    beer1 beverage

    B

    beer2 beverage

    C

    beverage beer1

    D

    编译失败


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

  • 第20题:

    名词解释题
    果汁饮料(fruit juice beverage)

    正确答案: 是指在果汁(浆)或浓缩果汁中加入水、食糖(或)甜味剂、酸味剂等调制而成的饮料,可加入柑橘类的囊胞(或其他水果经切细的果肉)等果粒。果汁含量≥10%(质量分数)。
    解析: 暂无解析

  • 第21题:

    单选题
    class One {  public One() { System.out.print(1); }  }  class Two extends One {  public Two() { System.out.print(2); }  }  class Three extends Two {  public Three() { System.out.print(3); }  }  public class Numbers{  public static void main( String[] argv) { new Three(); }  }  What is the result when this code is executed?()
    A

     1

    B

     3

    C

     123

    D

     321

    E

     The code rims with no output.


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

  • 第22题:

    单选题
    现有:  class Bird {  void talk() { System.out.print("chirp "); }         }  class Parrot2 extends Bird {  protected void talk() { System.out.print("hello ");        public static void main(String [] args) {  Bird [] birds = {new Bird(), new Parrot2 () };         for( Bird b : birds)          b.talk () ;         }         }  结果是什么 ?()
    A

     chirp chirp

    B

     hello hello

    C

     chirp hello

    D

    编译错误


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

  • 第23题:

    单选题
    现有:  class Cat {  Cat(int c) { System.out.print("cat" + c + " "); }  }  class SubCat extends Cat {  SubCat(int c) { super(5); System.out.print("cable "); }  SubCat() { this(4); }  public static void main(String [] args) {  SubCat s = new SubCat();  }  } 结果为:()
    A

    cat5

    B

    cable

    C

    cable cat5

    D

    cat5 cable


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