4, 4
4, 5
5, 4
5, 5
The code will not compile.
第1题:
public class Something {
public int addOne(final int x) {
return ++x;
}
}
这个比较明显。
错。int x 被修饰成final,意味着x 不能在addOne method 中被修改。
第2题:
下面函数的运行结果是( )。 #include <iostream> using namespace std; class A{ public: A(){} int Min(int a,int b){return a<b? a:b;} int Min(int a,int b,int c){ if(a<b)return a<c? a:c; else return b<c? b:c; } ~A(){} }; void main(){ A a; cout<<a.Min(1,2,3)<<a.Min(2,0); }
A.10
B.12
C.30
D.32
第3题:
A.Foo { public int bar() { return 1; }
B.new Foo { public int bar() { return 1; }
C.new Foo() { public int bar() { return 1; }
D.new class Foo { public int bar() { return 1; }
第4题:
Which statements concerning the following code are true?() class a { public a() {} public a(int i) { this(); } } class b extends a { public boolean b(String msg) { return false; } } class c extends b { private c() { super(); } public c(String msg) { this(); } public c(int i) {} }
第5题:
public class Person { private String name, comment; private int age; public Person(String n, int a, String c) { name = n; age = a; comment = c; } public boolean equals(Object o) { if(! (o instanceof Person)) return false; Person p = (Person)o; return age == p.age && name.equals(p.name); } } What is the appropriate definition of the hashCode method in class Person?()
第6题:
有如下程序: #include<iostream> using namespace std; class Base{ int x; public: Base(int n=0):x(n){cout<<n;) int getX()const{return x;} }; class Derived:public Base{ int y; public: Derived(int m,int n):y(m,)Base(n){cout<<m;} Derived(int m):y(m){cout<<m;} }; int main(){ Derived d1(3),d2(5,7) return 0; }运行时的输出结果是
A.375
B.357
C.375
D.357
第7题:
class A { protected int method1(int a, int b) { return 0; } } Which two are valid in a class that extends class A?()
第8题:
执行下列代码后,输出的结果为( )。 class Base { int x = 30; void setX( ) {x=1O;} } class SubClass extends Base { int x=40; void setX ( ) {x=20;} int getX( ) {return super. x; } } public class Test { public static void main(String[ ] args) { SubClass sub=new SubClass( ); sub. setX( ); System. out. println(sub, getX( ) ); } }
A.10
B.20
C.30
D.40
第9题:
class Super { public int getLenght( ) { return 4; } } public class Sub extends Super { public long getLenght( ) { return 5; } public static void main(String[] args) { Super sooper = new Super( ); Sub sub = new Sub( ); System.out.println( sooper.getLenght( ) + “,” + sub.getLenght( ) ); } } What is the output?()
第10题:
class super { public float getNum() {return 3.0f;} } public class Sub extends Super { } Which method, placed at line 6, will cause a compiler error?()