单选题11. class Payload {  12. private int weight;  13. public Payload(int wt) { weight = wt; }  13. public void setWeight(mt w) { weight = w; }  15. public String toString { return Integer.toString(weight); }  16. }  17.  18. public class TestPayload {  19.

题目
单选题
11. class Payload {  12. private int weight;  13. public Payload(int wt) { weight = wt; }  13. public void setWeight(mt w) { weight = w; }  15. public String toString { return Integer.toString(weight); }  16. }  17.  18. public class TestPayload {  19. static void changePayload(Payload p) { 20. /* insert code here */ 21. }  22.  23. public static void main(String[] args) {  24. Payload p = new Payload();  25. p.setWeight(1024);  26. changePayload(p);  27. System.out.println(”The value of p is “+ p);  28. }  29. }  Which statement, placed at line 20, causes the code to print “The value of p is 420.”?()
A

 p.setWeight(420);

B

 p.changePayload(420);

C

 p = new Payload(420);

D

 Payload.setWeight(420);

E

 p = Payload.setWeight(420);

F

 p = new Payload(); p.setWeight(420);

如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

10. interface Foo { int bar(); }  11. public class Sprite {  12. public int fubar( Foo foo) { return foo.bar(); }  13. public void testFoo() {  14. fubar(  15. // insert code here  16.);  17. }  18. }  Which code, inserted at line 15, allows the class Sprite to compile?() 

  • A、 Foo { public int bar() { return 1; } }
  • B、 new Foo { public int bar() { return 1; } }
  • C、 newFoo() { public int bar(){return 1; } }
  • D、 new class Foo { public int bar() { return 1; } }

正确答案:C

第2题:

1. package foo;  2.    3. import java.util.Vector;  4.    5. private class MyVector extends Vector {  6. int i = 1;  7. public MyVector()  {  8. i = 2;  9.    }  10. }  11.    12. public class MyNewVector extends MyVector {  13. public MyNewVector ()  {  14. i = 4;  15. }  16. public static void main (String args [])  {  17. MyVector v = new MyNewVector();  18.   }  19. }     The file MyNewVector.java is shown in the exhibit.  What is the result?()  

  • A、 Compilation will succeed.
  • B、 Compilation will fail at line 5.
  • C、 Compilation will fail at line 6.
  • D、 Compilation will fail at line 14.
  • E、 Compilation will fail at line 17.

正确答案:B

第3题:

请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,其中定义了vehiele类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将Vehicle作为虚基类,避免二义性问题。请在程序中的横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为:

80

150

100

1

注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。

include<iostream.h>

class vehicle

{

private:

int MaxSpeed;

int Weight;

public:

//*************found************

vehicle(int maxspeed,int weight):——

~vehicle{};

int getMaxSpeed{return MaxSpeed;}

int getWeight{retum Weight;}

};

//****************found************

class bicycle:——public vehicle

{

private:

int Height;

public:

bicycle(int maxspeed,int weight,int height):vehicle(maxspeed,weight),Height(height){}

int getHeight{retum Height;};

};

//*******************found**************

class motorcar:——public vehicle

{

private:

int SeatNum;

public:

motorcar(int maxspeed。int weight,int seatnum):vehicle(maxspeed,weight),SeatNum(seatnum){}

int getSeatNum{return SeatNum;};

};

//*****************found***************

class motorcycle:——

{

public:

motorcycle(int maxspeed,int weight,int height):vehicle(maxspeed,weight),bicycle(maxspeed,weight,

height),motorcar(maxspeed,weight,1){}

};

void main

{

motorcycle a(80,150,100);

cout<<a.getMaxSpeed<<endl;

cout<<a.getWeight<<endl;

cout<<a.getHeight<<endl;

cout<<a.getSeatNum<<endl;

}


正确答案:

(1)MaxSpeed(maxspeed),Weight(weight){f;

(2)virtual

(3)virtua1

(4)public bicycle,public motorcar


第4题:

11. public class Test {  12. public void foo() {  13. assert false;  14. assert false;  15. }  16. public void bar(){  17. while(true){  18. assert false;  19. }  20. assert false;  21. }  22. }  What causes compilation to fail?()  

  • A、 Line 13
  • B、 Line 14
  • C、 Line 18
  • D、 Line 20

正确答案:D

第5题:

11. class Animal { public String noise() { return “peep”; } }  12. class Dog extends Animal {  13. public String noise() { return “bark”; }  14. }  15. class Cat extends Animal {  16. public String noise() { return “meow”; }  17. }  .....  30. Animal animal = new Dog();  31. Cat cat = (Cat)animal;  32. System.out.printIn(cat.noise());  What is the result?() 

  • A、 peep
  • B、 bark
  • C、 meow
  • D、 Compilation fails.
  • E、 An exception is thrown at runtime.

正确答案:E

第6题:

10. abstract public class Employee {  11. protected abstract double getSalesAmount();  12. public double getCommision() {  13. return getSalesAmount() * 0.15;  14. }  15. }  16. class Sales extends Employee {  17. // insert method here  18. }  Which two methods, inserted independently at line 17, correctly complete the Sales class?()

  • A、 double getSalesAmount() { return 1230.45; }
  • B、 public double getSalesAmount() { return 1230.45; }
  • C、 private double getSalesAmount() { return 1230.45; }
  • D、 protected double getSalesAmount() { return 1230.45; }

正确答案:B,D

第7题:

1. public class Test { 2. public static String output =””; 3.  4. public static void foo(int i) { 5. try { 6. if(i==1) { 7. throw new Exception(); 8. } 9. output += “1”; 10. } 11. catch(Exception e) { 12. output += “2”; 13. return; 14. } 15. finally { 16. output += “3”;17. } 18. output += “4”; 19. } 20.  21. public static void main(String args[]) { 22. foo(0); 23. foo(1); 24.  25. }26. } What is the value of the variable output at line 23?()


正确答案:13423

第8题:

请问下述代码中: int operator+(…)起什么作用?this 是什么?ccc 的值最终为多少?

class Fruit

{

public:

Fruit()

{

weight = 2;

}

Fruit(int w)

{

weight = w;

}

int operator+(Fruit f)

{

return this->weight * f.weight;

}

private:

int weight;

};

Fruit aaa;

Fruit bbb(4);

int ccc = aaa + bbb;


正确答案:
 

第9题:

public class Score implements Comparable {  private int wins, losses;  public Score(int w, int 1) { wins = w; losses = 1; }  public int getWins() { return wins; }  public int getLosses() { return losses; }  public String toString() {  return “<“ + wins + “,“ + losses + “>”; }  // insert code here  }  Which method will complete this class?() 

  • A、 public int compareTo(Object o) {/*mode code here*/}
  • B、 public int compareTo(Score other) {/*more code here*/}
  • C、 public int compare(Score s1,Score s2){/*more code here*/}
  • D、 public int compare(Object o1,Object o2){/*more code here*/}

正确答案:B

第10题:

11. class Payload {  12. private int weight;  13. public Payload(int wt) { weight = wt; }  13. public void setWeight(mt w) { weight = w; }  15. public String toString { return Integer.toString(weight); }  16. }  17.  18. public class TestPayload {  19. static void changePayload(Payload p) { 20. /* insert code here */ 21. }  22.  23. public static void main(String[] args) {  24. Payload p = new Payload();  25. p.setWeight(1024);  26. changePayload(p);  27. System.out.println(”The value of p is “+ p);  28. }  29. }  Which statement, placed at line 20, causes the code to print “The value of p is 420.”?() 

  • A、 p.setWeight(420);
  • B、 p.changePayload(420);
  • C、 p = new Payload(420);
  • D、 Payload.setWeight(420);
  • E、 p = Payload.setWeight(420);
  • F、 p = new Payload(); p.setWeight(420);

正确答案:A

更多相关问题