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);

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);

相关考题:

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

请问下述代码中: 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;

1. class A {  2. public int getNumber(int a) {  3.     return a + 1;  4. }  5. }  6.    7. class B extends A {  8. public int getNumber (int a) {  9. return a + 2  10. }  11.    12. public static void main (String args[])  {  13. A a = new B();  14. System.out.printIn(a.getNumber(0));  15.    } 16. }     What is the result?()  A、 Compilation succeeds and 1 is printed.B、 Compilation succeeds and 2 is printed.C、 An error at line 8 causes compilation to fail.D、 An error at line 13 causes compilation to fail.E、 An error at line 14 causes compilation to fail.

1. class Super {  2. private int a;  3. protected Super(int a) { this.a = a; }  4. }  .....  11. class Sub extends Super {  12. public Sub(int a) { super(a); }  13. public Sub() { this.a= 5; }  14. }  Which two, independently, will allow Sub to compile?()A、 Change line 2 to: public int a;B、 Change line 2 to: protected int a;C、 Change line 13 to: public Sub() { this(5); }D、 Change line 13 to: public Sub() { super(5); }E、 Change line 13 to: public Sub() { super(a); }

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; } }

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; }

11. static class A {  12. void process() throws Exception { throw new Exception(); }  13. }  14. static class B extends A {  15. void process() { System.out.println(”B”); }  16. }  17. public static void main(String[] args) {  18. new B().process();  19. }  What is the result?() A、 BB、 The code runs with no output.C、 Compilation fails because of an error in line 12.D、 Compilation fails because of an error in line 15.E、 Compilation fails because of an error in line 18.

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.

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?()

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、 peepB、 barkC、 meowD、 Compilation fails.E、 An exception is thrown at runtime.

1. class A {  2. public String toString ()  {  3. return “4”;  4. }  5. }  6. class B extends A {  7. public String toString ()   {  8. return super.toString()  + “3”;  9. }  10. }  11. public class Test {  12.   public static void main(String[]args)  {  13.      System.out.printIn(new B());  14.      }  15. }    What is the result?()  A、 Compilation succeeds and 4 is printed.B、 Compilation succeeds and 43 is printed.C、 An error on line 9 causes compilation to fail.D、 An error on line 14 causes compilation to fail.E、 Compilation succeeds but an exception is thrown at line 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*/}

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 13B、 Line 14C、 Line 18D、 Line 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();

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、 4321B、 0000C、 An exception is thrown at runtime.D、 Compilation fails because of an error in line 18.

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.

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);

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、 HelloB、 Hello WorldC、 Compilation fails.D、 Hello World 5E、 The code runs with no output.F、 An exception is thrown at runtime.

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.

public abstract class Shape {  private int x;  private int y;  public abstract void draw();  public void setAnchor(int x, int y) {  this.x = x;  this.y = y;  }  }  Which two classes use the Shape class correctly?()A、 public class Circle implements Shape { private int radius; }B、 public abstract class Circle extends Shape { private int radius; }C、 public class Circle extends Shape { private int radius; public void draw(); }D、 public abstract class Circle implements Shape { private int radius; public void draw(); }E、 public class Circle extends Shape { private int radius;public void draw() {/* code here */} }F、 public abstract class Circle implements Shape { private int radius;public void draw() { / code here */ } }

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();

多选题1. class Super {  2. private int a;  3. protected Super(int a) { this.a = a; }  4. }  .....  11. class Sub extends Super {  12. public Sub(int a) { super(a); }  13. public Sub() { this.a= 5; }  14. }  Which two, independently, will allow Sub to compile?()AChange line 2 to: public int a;BChange line 2 to: protected int a;CChange line 13 to: public Sub() { this(5); }DChange line 13 to: public Sub() { super(5); }EChange line 13 to: public Sub() { super(a); }

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

单选题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 peepB barkC meowD Compilation fails.E An exception is thrown at runtime.

多选题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?()Adouble getSalesAmount() { return 1230.45; }Bpublic double getSalesAmount() { return 1230.45; }Cprivate double getSalesAmount() { return 1230.45; }Dprotected double getSalesAmount() { return 1230.45; }

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

单选题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 13B Line 14C Line 18D Line 20