A. 0 B. 99 C. 100 D. 101
正确答案:A 31.
请看下列代码: class Payload {
private int weight; public Payload(int wt) { weight = wt; }
public Payload() {}
public void setWeight(int w) { weight = w; }
public String toString() {
return Integer.toString(weight); } }
public class TestPayload {
static void changePayload(Payload p) {
<插入代码> }
public static void main(String[] args) { Payload p = new Payload(); p.setWeight(1024); changePayload(p);
System.out.println(\ } }
假设运行后输出“The value of p is 420”,那么<插入代码>处应填入代码是:a A.
p.setWeight(420);
B.
Payload.setWeight(420); C.
p = new Payload(420); D.
p = new Payload(); p.setWeight(420);
正确答案:A 32.
请看下列程序的输出结果是:d public class Item { private String desc;
public String getDescription() { return desc; }
public void setDescription(String d) { desc = d; }
public static void modifyDesc(Item item, String desc) { item = new Item();
item.setDescription(desc); }
public static void main(String[] args) { Item it = new Item();
it.setDescription(\ Item it2 = new Item();
it2.setDescription(\
modifyDesc(it, \ System.out.println(it.getDescription()); System.out.println(it2.getDescription()); } } A.
Scrumdiddlyumptious Scrumdiddlyumptious B.
Scrumdiddlyumptious Fizzylifltng C.
Gobstopper
Scrumdiddlyumptious D.
Gobstopper
Fizzylifting
正确答案:D 33.
下列代码运行的结果是(d)。
public class Base {
public static final String 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 = \} A.
foofoofoofoofoo B.
foobarfoobarbar C.
foobarfoofoofoo D.
foobarfoobarfoo
正确答案:D 34.
下列代码的输出结果是(c)。 abstract class Vehicle { public int speed() { return 0; } }
class Car extends Vehicle { public int speed() { return 60; } }
class RaceCar extends Car { public int speed() { return 150; } }
public class TestCar {
public static void main(String[] args) { RaceCar racer = new RaceCar(); Car car = new RaceCar();
Vehicle vehicle = new RaceCar();
System.out.println(racer.speed() + \ + vehicle.speed()); } } A. 0, 0,0 B. 150, 60, 0 C.
150, 150, 150 D.
抛出运行时异常
正确答案:C 35.
程序的执行结果是:a public class Test {
public static void main(String [] args){ String str1= new String(\ String str2 = new String(\ String str3=str1; if(str1.equals(str2)){
System.out.println(\ }else{
System.out.println(\ }
if(str1==str3){
System.out.println(\ }else{
System.out.println(\ } }
A. true true B. true false C. false true D. false false
正确答案:A 1.
请看下列代码: class One {
public One foo() { return this; } }
class Two extends One { public One foo() { return this; } }
class Three extends Two { <插入代码> }
下列选项中的代码,放置在<插入代码>处无编译错误的是:CD A.
public void foo() { } B.
public Object foo() { return this; } C.
public Two foo() { return this; } D.
public One foo() { return this; }
正确答案:CD