niusouti.com

单选题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.请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,其中定义了vehiele类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将Vehicle作为虚基类,避免二义性问题。请在程序中的横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为:801501001注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****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;}

更多“单选题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.”相关问题
  • 第1题:

    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

  • 第2题:

    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

  • 第3题:

    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

  • 第4题:

    10. public class Foo implements java.io.Serializable {  11. private int x;  12. public int getX() { return x; }  12.publicFoo(int x){this.x=x; }  13. private void writeObject( ObjectOutputStream s)  14. throws IOException {  15. // insert code here  16. }  17. }  Which code fragment, inserted at line 15, will allow Foo objects to be correctly serialized and deserialized?() 

    • A、 s.writeInt(x);
    • B、 s.serialize(x);
    • C、 s.writeObject(x);
    • D、 s.defaultWriteObject();

    正确答案:D

  • 第5题:

    1. class A {  3. public String to String() {  4. return “4”;  5. }  6. }  7. class B extends A {  8. public String toString() { 9. return super.toString() + “3”;  10. }  11. }  12. public class Test {  13. public static void main (String[] args) {  14. System.out.printIn(new B()); 15. }  16. }   What is the result( )?  

    • A、 Compilation succeeds and 4 is printed.
    • B、 Compilation …………… is printed.
    • C、 An error on line 9 cause compilation to fail.
    • D、 An error on line 14 cause compilation to fail.
    • E、 Compilation succeeds but an exception is thrown at line 9.

    正确答案:B

  • 第6题:

    10. public class Hello {  11. String title;  12. int value;  13. public Hello() {  14. title += “ World”;  15. }  16. public Hello(int value) {  17. this.value = value;  18. title = “Hello”;  19. Hello();  20. }  21. }  and:  30. Hello c = new Hello(5);  31. System.out.println(c.title);  What is the result?() 

    • A、 Hello
    • B、 Hello World
    • C、 Compilation fails.
    • D、 Hello World 5
    • E、 The code runs with no output.
    • F、 An exception is thrown at runtime.

    正确答案:C

  • 第7题:

    10. class Line {  11. public class Point { public int x,y; }  12. public Point getPoint() { return new Point(); }  13. }  14. class Triangle {  15. public Triangle() {  16. // insert code here  17. }  18. }  Which code, inserted at line 16, correctly retrieves a local instance of a Point object?() 

    • A、 Point p = Line.getPoint();
    • B、 Line.Point p = Line.getPoint();
    • C、 Point p = (new Line()).getPoint();
    • D、 Line.Point p = (new Line()).getPoint();

    正确答案:D

  • 第8题:

    单选题
    11. class Person {  12. String name = “No name‟;  13. public Person(String nm) { name = nm; }  14. }  15.  16. class Employee extends Person {  17. String emplD = “0000”;  18. public Employee(String id) { empID = id; }  19. }  20.  21. public class EmployeeTest {  22. public static void main(String[] args) {  23. Employee e = new Employee(”4321”);  24. System.out.println(e.empID);  25. }  26. }  What is the result?()
    A

     4321

    B

     0000

    C

     An exception is thrown at runtime.

    D

     Compilation fails because of an error in line 18.


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

  • 第9题:

    单选题
    10. class Line {  11. public class Point { public int x,y; }  12. public Point getPoint() { return new Point(); }  13. }  14. class Triangle {  15. public Triangle() {  16. // insert code here  17. }  18. }  Which code, inserted at line 16, correctly retrieves a local instance of a Point object?()
    A

     Point p = Line.getPoint();

    B

     Line.Point p = Line.getPoint();

    C

     Point p = (new Line()).getPoint();

    D

     Line.Point p = (new Line()).getPoint();


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

  • 第10题:

    单选题
    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
    解析: 暂无解析

  • 第11题:

    单选题
    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
    解析: 暂无解析

  • 第12题:

    单选题
    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
    解析: 暂无解析

  • 第13题:

    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

  • 第14题:

    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

  • 第15题:

    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

  • 第16题:

    11. class Person {  12. String name = “No name‟;  13. public Person(String nm) { name = nm; }  14. }  15.  16. class Employee extends Person {  17. String emplD = “0000”;  18. public Employee(String id) { empID = id; }  19. }  20.  21. public class EmployeeTest {  22. public static void main(String[] args) {  23. Employee e = new Employee(”4321”);  24. System.out.println(e.empID);  25. }  26. }  What is the result?() 

    • A、 4321
    • B、 0000
    • C、 An exception is thrown at runtime.
    • D、 Compilation fails because of an error in line 18.

    正确答案:D

  • 第17题:

    10. class Inner {  11. private int x;  12. public void setX( int x) { this.x = x; }  13. public int getX() { return x; }  14. }  15.  16. class Outer {  17. private Inner y;  18. public void setY( Inner y) { this.y = y; }  19. public Inner getY() { return y; }  20. }  21.  22. public class Gamma {  23. public static void main( String[] args) { 24. Outer o = new Outer(); 25. Inner i = new Inner();  26.int n=10;  27. i.setX(n);  28. o.setY(i);  29. // insert code here  30. System.out.println( o.getY().getX());  31. }  32. }  Which three code fragments, added individually at line 29, produce the output 100?()

    • A、 n = 100;
    • B、 i.setX( 100);
    • C、 o.getY().setX( 100);
    • D、 i = new Inner(); i.setX( 100);
    • E、 o.setY( i); i = new Inner(); i.setX( 100);
    • F、 i = new Inner(); i.setX( 100); o.setY( i);

    正确答案:B,C,F

  • 第18题:

    10. interface Foo {  11. int bar();  12. }  13.  14. public class Beta {  15.  16. class A implements Foo {  17. public int bar() { return 1; }  18. }  19.  20. public int fubar( Foo foo) { return foo.bar(); }  21.  22. public void testFoo() {  23.  24. class A implements Foo {  25. public int bar() { return 2; }  26. }  27.  28. System.out.println( fubar( new A())); 29. }  30.  31. public static void main( String[] argv) {  32. new Beta().testFoo();  33. }  34. }  Which three statements are true?()

    • A、 Compilation fails.
    • B、 The code compiles and the output is 2.
    • C、 If lines 16, 17 and 18 were removed, compilation would fail.
    • D、 If lines 24, 25 and 26 were removed, compilation would fail.
    • E、 If lines 16, 17 and 18 were removed, the code would compile and the output would be 2.
    • F、 If lines 24, 25 and 26 were removed, the code would compile and the output would be 1.

    正确答案:B,E,F

  • 第19题:

    单选题
    10. public class Hello {  11. String title;  12. int value;  13. public Hello() {  14. title += “ World”;  15. }  16. public Hello(int value) {  17. this.value = value;  18. title = “Hello”;  19. Hello();  20. }  21. }  and:  30. Hello c = new Hello(5);  31. System.out.println(c.title);  What is the result?()
    A

     Hello

    B

     Hello World

    C

     Compilation fails.

    D

     Hello World 5

    E

     The code runs with no output.

    F

     An exception is thrown at runtime.


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

  • 第20题:

    单选题
    10. public class Foo implements java.io.Serializable {  11. private int x;  12. public int getX() { return x; }  12.publicFoo(int x){this.x=x; }  13. private void writeObject( ObjectOutputStream s)  14. throws IOException {  15. // insert code here  16. }  17. }  Which code fragment, inserted at line 15, will allow Foo objects to be correctly serialized and deserialized?()
    A

     s.writeInt(x);

    B

     s.serialize(x);

    C

     s.writeObject(x);

    D

     s.defaultWriteObject();


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

  • 第21题:

    单选题
    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 “”; }  // 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
    解析: 暂无解析

  • 第22题:

    单选题
    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; } }


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

  • 第23题:

    单选题
    1. class A {  3. public String to String() {  4. return “4”;  5. }  6. }  7. class B extends A {  8. public String toString() { 9. return super.toString() + “3”;  10. }  11. }  12. public class Test {  13. public static void main (String[] args) {  14. System.out.printIn(new B()); 15. }  16. }   What is the result( )?
    A

     Compilation succeeds and 4 is printed.

    B

     Compilation …………… is printed.

    C

     An error on line 9 cause compilation to fail.

    D

     An error on line 14 cause compilation to fail.

    E

     Compilation succeeds but an exception is thrown at line 9.


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