beer1 beverage
beer2 beverage
beverage beer1
编译失败
第1题:
interface A{
int x = 0;
}
class B{
int x =1;
}
class C extends B implements A {
public void pX(){
System.out.println(x);
}
public static void main(String[] args) {
new C().pX();
}
}
错误。在编译时会发生错误(错误描述不同的JVM 有不同的信息,意思就是未明确的
x 调用,两个x 都匹配(就象在同时import java.util 和java.sql 两个包时直接声明Date 一样)。
对于父类的变量,可以用super.x 来明确,而接口的属性默认隐含为 public static final.所以可
以通过A.x 来明确。
第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
第3题:
public class Base { public static final String FOO = “foo”; public static void main(String[] args) { Base b = new Base(); Sub s = new Sub(); System.out.print(Base.FOO); System.out.print(Sub.FOO); System.out.print(b.FOO); System.out.print(s.FOO); System.out.print(((Base)s).FOO); } } class Sub extends Base {public static final String FOO=bar;} What is the result?()
第4题:
class Flibitz { public static void main(String [] args) { int grop = 7; new Flibitz().go(grop); System.out.print(grop); } void go(int grop) { if(++grop 〉 7) grop++; System.out.print(grop); } } 结果为:()
第5题:
class Top { static int x = 1; public Top(int y) { x *= 3; } } class Middle extends Top { public Middle() { x += 1; } public static void main(String [] args) { Middle m = new Middle(); System.out.println(x); } } 结果为:()
第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("beer1 "); } public Beer() { System.out.print("beer2 "); } } 结果是什么?()
第7题:
class Parser extends Utils { public static void main(String [] args) { System.out.print(new Parser().getInt("42")); } int getInt(String arg) { return Integer.parseInt(arg); } } class Utils { int getInt(String arg) throws Exception { return 42; } } 结果为:()
第8题:
cat5
cable
cat5 cable
cable cat5
第9题:
chirp chirp
chirp hello
hello hello
编译失败
第10题:
Shape
Circle
ShapeCircle
程序有错误
第11题:
55
56
65
66
第12题:
1
2
3
编译失败
第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
第14题:
A.编译错误
B.200
C.100200
D.100
第15题:
程序: class TestReference{ public static void main(String[] args){ int x=2; TestReference tr = new TestReference(); System.out.print(x); tr.change(x); System.out.print(x); } public void change(int num){ num = num + 1; } } 程序运行后的输出是哪项?()
第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(); } } 结果为:()
第17题:
class Passer { static final int x = 5; public static void main(String [] args) { new Passer().go(x); System.out.print(x); } void go(int x) { System.out.print(++x); } } 结果是什么?()
第18题:
现有 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 "); } } 结果是什么?()
第19题:
beerl beverage
beer2 beverage
beverage beer2 beerl
编译失败
第20题:
cat5
cable
cable cat5
cat5 cable
第21题:
77
79
97
99
第22题:
23
21
22
编译错误
第23题:
beer1 beverage
beer2 beverage
beverage beer1
编译失败
第24题:
foofoofoofoofoo
foobarfoobarbar
foobarfoofoofoo
foobarfoobarfoo
barbarbarbarbar
foofoofoobarbar
foofoofoobarfoo