4, 4
4, 5
5, 4
5, 5
The code will not compile.
第1题:
执行下列代码后,输出的结果为( )。 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
第2题:
class A { protected int method1(int a, int b) { return 0; } } Which two are valid in a class that extends class A?()
第3题:
若类A和类B的定义如下: #include<malloc.h> class A { int i,j; public: int geti() { return i; } }; class B:public A { int k; public: void make() { k=i*j; } }; 则上述定义中非法的表达式是( )。
A.k=i*j
B.int k;
C.return i;
D.void make();
第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题:
1. public class Target { 2. private int i = 0; 3. public int addOne() { 4. return ++i; 5. } 6. } And: 1. public class Client { 2. public static void main(String[] args) { 3. System.out.println(new Target().addOne()); 4. } 5. } Which change can you make to Target without affecting Client?()
第6题:
public class Something {
public int addOne(final int x) {
return ++x;
}
}
这个比较明显。
错。int x 被修饰成final,意味着x 不能在addOne method 中被修改。
第7题:
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?()
第8题:
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; }
第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?()