文档介绍:IBM-Java笔试题
class A {
AO { }
}
class B extends A {
)
哪两个说明是正确的?
B类的构造器应该是public.
B类的构造器应该是没有参数
B类的构造器应该调用this ().
B类的构造器应该调用super ().
答案:BD 解 析:默认构造器的修饰符只跟当前类的修饰 符有关。比如B如果是public的,则默认构造 方法是public的。如果B是默认的访问权限, 则构造方法相同。当B是内部类是,前面也可 以有
protected, private等,默认添加的构造 方法仍然和类的修饰符一致。
public class Test { public int aMethod() { static int i = 0;
return i;
}
public static void main (String args[]) {
Test test = new Test ();
test. aMethod ();
int j = test. aMethod ();
System, out. println(j);
)
)
输出结果是什么?
0
1
2
答案:D 解析:static在Java语言中的使用有四种:(成 员变量、成员方法、代码块、内部类)
int i =1, j =10; do {
if(i > —j) {
continue; ) } while (i <5);
System, out. printin(^i = " i "and j = ' j);
输出结果是什么?
A.
B.
C.
D.
E.
i = 6
i = 5
i = 6
i = 5
i = 6
and j = and j = and j = and j = and j =
5
5
5
6
6
答案:D
: boolean bool = true; if(bool = false) { System, out. printin (^a^); } else if (bool) { System, out. printin("c"); } else if (Ibool) { System, out. printin("c"); } else {
System, out. printin(^d^); )
输出结果是什么?
a
b
c
d
答案:c
public class SwitchTest {
public static void main(String[] args) {
System, out. printin("value ="switchlt(4)); )
public static int switchlt(int x) {
int j = 1;
switch (x) {
j ;
j ;
j ;
j ;
j ;
default: j ;
)
return j x;
)
}
输出结果是什么?
value = 3
value = 4
value = 5
value = 6
value = 7
value = 8
答案:F
.以下数组的定义,哪三条是正确的?
public int a []
static int 口 a
public 口 int a
private int a [3]
private int [3] a []
public final int 口 a 答案:A, B,F
.如下代码: class Super {
return new
public Integer getLenght ()
Integer(4); } ) public class Sub extends Super { public Long GetLenght() { return new
Long ⑸;} public static void main(String[] args) { Super sooper 二 new Super();
Sub sub = new Sub ();
System, out. printin(sooper. getLenght() • toS tring ()” sub. getLenght (). toString ());
) ) 输出是什么? A. 4,4 B. 4,5 C. 5,4 D. 5,5 E.
编译失败. 答案:A
.在接口中以下哪条定义是正确的?(两个答 案)
void