达内corejava第二次考试
试题类型:单选题
试题1
已知变量a和obj的定义如下:
Object[] a1 = { "a", "b", "c" };
Object obj = a1;
则下面语句运行时会抛出异常的是( )。C
A.
Object[] a2 = (Object[])obj;
B.
String str1 = (String)((Object[])obj)[1]
C.
String[] a3 = (String[])obj
D.
String str2 = (String)a1[2]
试题2
已知类Foo的定义如下:
public class Foo {
int value;
Foo(int value) {
this.value = value;
}
}
运行下面程序段:
Foo[] a1 = { new Foo(1), new Foo(2), new Foo(3) };            Foo[] a2 = new Foo[a1.length];
System.arraycopy(a1, 0, a2, 0, a1.length);
System.out.println((a1 == a2) + "," + (a1[1] == a2[1]));
控制台输出的结果是( )。A
A.false,true
B.false,false
试题3
已知类Foo的定义如下:
public class Foo {
int value;
Foo(int value) {
this.value = value;
}
public boolean equals(Object obj) {
if (obj instanceof Foo) {
Foo foo = (Foo) obj;
return value == foo.value;
} else {
return false;
}
}
运行下面程序段:
ArrayList list = new ArrayList();
HashSet set = new HashSet();
list.add(new Foo(1));
set.add(new Foo(1));
System.out.ains(new Foo(1)) + ","                        + ains(new Foo(1)));
控制台输出的结果是( )。A
C.false,false
D.alse,true
试题4
已知类A、B、C和接口D的定义如下:
java做什么的public class A{…}
public class B extends A implements D {…}
public class C extends A {…}
public interface D {…}
变量a、b、c、d的定义如下:
A a = new A();
B b = new B();
C c = new C();
D d = null;
则下列语句会有编译错误的是( )。D
A.a = b;
B.d = b;
C.d = (D)a;
D.c = (C)b;
试题5
运行如下代码:
class COne {
public void f() {
System.out.println("COne.f");
}
}
class CTwo extends COne{
public void f() {
System.out.println("CTwo.f");
}
}
class CThree {
public void g(COne one) {
System.out.println("g(Cone)");
one.f();
}
public void g(CTwo two) {
System.out.println("g(Ctwo)");
two.f();
}
}
public class Main {
public static void main(String[] args) {
COne one = new CTwo();
CThree three = new CThree();
three.g(one);
}
}
控制台输出的结果是( )。 A
A.g(Cone)
CTwo.f
B.g(Cone)
COne.f
C.g(Ctwo)
CTwo.f
D.g(Ctwo)
COne.f
试题6
运行如下代码
class Foo {
private int value = 5;
public Foo() {
System.out.println("Foo()");
System.out.println(value);
}
}
class Bar extends Foo{
private int value = 10;
public Bar() {
System.out.println("Bar()");
System.out.println(value);
}
}
public class Main {
public static void main(String[] args) {        Bar bar = new Bar();
}
}
控制台输出的结果是( )。B
A.
Bar()
10
Foo()
5
B.
Foo()
5
Bar()
10
C.
Bar()
5
Foo()
10</texta
D.
Foo()
10
Bar()
5
试题7
实现Point类的equals方法,具体逻辑为:“成员变量x和y分别相等的Point对象被视为相等”。    public class Point {
private int x;
private int y;
...
public boolean equals(Object obj) {
填入代码
}
}
以下代码正确的是( )。D

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。