A
B
C
D
E
F
第1题:
下列程序的输出结果是 #include"iostream" using namespace std; int Max(int a,int b) { if(a>b) return a; else return b; } void main( ) { int m,n; m=10,n=5; int max = Max(m,n); cout<<max<<endl; }
A.10
B.程序有误
C.1
D.0
第2题:
下列程序的输出结果为【 】。
inelude<iostream. h>
int &max(int &x, int &y)
{return (x>y? x: y); }
void main() {
int n=3, m=12;
max(m, n)++
cout<<"m="<<m<<", n= "<<n<<end1;
}
第3题:
11. public void testIfA() { 12. if(testIfB(”True”)) { 13. System.out.println(”True”); 14. } else { 15. System.out.println(”Not true”); 16. } 17. } 18. public Boolean testIfB(String str) { 19. return Boolean.valueOf(str); 20. } What is the result when method testIfA is invoked?()
第4题:
11. public class Counter { 12. public static void main(String[] args) { 13. int numArgs = /* insert code here */; 14. } 15. } and the command line: java Counter one fred 42 Which code, inserted at line 13, captures the number of arguments passed into the program?()
第5题:
public class X { public X aMethod() { return this;} } public class Y extends X { } Which two methods can be added to the definition of class Y?()
第6题:
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?()
第7题:
interface A { public int getValue() } class B implements A { public int getValue() { return 1; } } class C extends B { // insert code here } Which three code fragments, inserted individually at line 15, make use of polymorphism?()
第8题:
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?()
第9题:
Given: 10. class One { 11. void foo() { } 12. } 13. class Two extends One { 14. //insert method here 15. } Which three methods, inserted individually at line 14, will correctly complete class Two?()
第10题:
args.count
args.length
args.count()
args.length()
args.getLength()
第11题:
Point p = Line.getPoint();
Line.Point p = Line.getPoint();
Point p = (new Line()).getPoint();
Line.Point p = (new Line()).getPoint();
第12题:
double getSalesAmount() { return 1230.45; }
public double getSalesAmount() { return 1230.45; }
private double getSalesAmount() { return 1230.45; }
protected double getSalesAmount() { return 1230.45; }
第13题:
fun函数的功能是首先对a所指的N行N列的矩阵找出各行中最大的数,再求这N个最大值中最小的那个数作为函数值返回,请填空。#include <stdio.h>#define N 100int fun(int(*a)[N]){ int row,col,max,min; for(row=0;row<N;row++) { for(max=a[row][0],col=1;col<N;col++) if() max=a[row][col]; if(row==0) min=max; else if() min=max; } return min;}
第14题:
有以下程序: #include<iostream> using namespace std; Class sample { private: int n; public: sample(){} sample(int m) { n=m; } sample add(sample s1,samplc s2) { this-->n=s1.n+s2.n; return(*this); } void disp(
A.n=10
B.n=5
C.n=20
D.n=15
第15题:
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?()
第16题:
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?()
第17题:
public class Score implements Comparable
第18题:
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.”?()
第19题:
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?()
第20题:
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?()
第21题:
n = 100;
i.setX( 100);
o.getY().setX( 100);
i = new Inner(); i.setX( 100);
o.setY( i); i = new Inner(); i.setX( 100);
i = new Inner(); i.setX( 100); o.setY( i);
第22题:
A
B
C
D
E
F
第23题:
True
Not true
An exception is thrown at runtime.
Compilation fails because of an error at line 12.
Compilation fails because of an error at line 19.
第24题:
p.setWeight(420);
p.changePayload(420);
p = new Payload(420);
Payload.setWeight(420);
p = Payload.setWeight(420);
p = new Payload(); p.setWeight(420);