`
wangleide414
  • 浏览: 592035 次
  • 性别: Icon_minigender_1
  • 来自: 西安
社区版块
存档分类
最新评论
阅读更多

 

1. 如下代码
class A {
A() { }
}

class B extends A {
}
哪两个说明是正确的?
A. B类的构造器应该是 public.
B. B类的构造器应该是没有参数
C. B类的构造器应该调用this().
D. B类的构造器应该调用super().


2. 如下代码
public class Test {
public int aMethod() {
static int i = 0;
i++;
return i;
}
public static void main (String args[]) {
Test test = new Test();
test.aMethod();
int j = test.aMethod();
System.out.println(j);
}
}
输出结果是什么?
A. 0
B. 1
C. 2
D. 编译失败


3. 如下代码
int i =1,j =10;
do {
if(i++> --j) {
continue;
}
} while (i <5);
System.out.println("i = " +i+ "and j = "+j);
输出结果是什么?
A. i = 6 and j = 5
B. i = 5 and j = 5
C. i = 6 and j = 5
D. i = 5 and j = 6
E. i = 6 and j = 6


4. 如下代码:
boolean bool = true;
if(bool = false) {
System.out.println("a");
} else if (bool) {
System.out.println("c");
} else if (!bool) {
System.out.println("c");
} else {
System.out.println("d");
}
输出结果是什么?
A. a
B. b
C. c
D. d
E. 编译失败


5. 如下代码:
public class SwitchTest {
public static void main(String[] args) {
System.out.println("value = " + switchIt(4));
}
public static int switchIt(int x) {
int j = 1;
switch (x) {
case 1: j++;
case 2: j++;
case 3: j++;
case 4: j++;
case 5: j++;
default: j++;
}
return j + x;
}
}
输出结果是什么?
A. value = 3
B. value = 4
C. value = 5
D. value = 6
E. value = 7
F. value = 8


6. 以下数组的定义,哪三条是正确的?
A. public int a []
B. static int [] a
C. public [] int a
D. private int a [3]
E. private int [3] a []
F. public final int [] a


7. 如下代码:
class Super {
public Integer getLenght() { return new Integer(4); }
}

public class Sub extends Super {
public Long GetLenght() { return new Long(5); }
public static void main(String[] args) {
Super sooper = new Super();
Sub sub = new Sub();
System.out.println(sooper.getLenght().toString() + "," +
sub.getLenght().toString() );
}
}
输出是什么?
A. 4,4
B. 4,5
C. 5,4
D. 5,5
E. 编译失败.


8. 在接口中以下哪条定义是正确的? (两个答案)
A. void methoda();
B. public double methoda();
C. public final double methoda();
D. static void methoda(double d1);
E. protected void methoda(double d1);


9. 如下代码:
public void test(int x) {
int odd = x%2;
if (odd) {
System.out.println("odd);
} else {
System.out.println("even");
}
}
哪个描述正确?
A. 编译失败.
B. "odd" 永远被输出.
C. "even" 永远被输出
D. "odd" 输出x的值,
E. "even" 输出x的值


10. 如下代码:
public class X {
public X aMethod() { return this;}
}
public class Y extends X {

}
哪两个方法能加到Y类的定义中?
A. public void aMethod() {}
B. private void aMethod() {}
C. public void aMethod(String s) {}
D. private Y aMethod() { return null; }
E. public X aMethod() { return new Y(); }


11. 如下代码:
public class X {
public static void main(String [] args) {
try {
badMethod();
System.out.print("A");
}
catch (Exception ex) {
System.out.print("C");
}
finally {
System.out.print("B");
}
System.out.print("D");
}
public static void badMethod() {
throw new Error();
}
}
结果是什么?
A. ABCD
B. 编译失败.
C. 显示C,退出程序.
D. 显示B,C,退出程序.
E. 显示BCD,退出程序.


12. 如下代码:
class Exc0 extends Exception { }
class Exc1 extends Exc0 { }
public class Test {
public static void main(String args[]) {
try {
throw new Exc1();
} catch (Exc0 e0) {
System.out.println("Ex0 caught");
} catch (Exception e) {
System.out.println("exception caught");
}
}
}
结果是什么?
A. Ex0 caught
B. exception caught
C.第2行出错,编译失败.
D. 第6行出错,编译失败.


13. 以下哪四个能使用throw抛出?
A. Error
B. Event
C. Object
D. Throwable
E. Exception
F. RuntimeException


14. 如下代码:
public class X (
private static int a;
public static void main(String [] args) {
modify(a);
System.out.println(a);
}
public static void modify(int a) {
a++;
}
}
结果是什么?
A. 0
B. 1
C. 编译失败.
D. 抛出运行时异常.


15. 如下代码:
int i = 0;
for (; i <4; i += 2) {
System.out.print(i + "");
}
System.out.println(i);
输出结果是什么?
A. 0 2 4
B. 0 2 4 5
C. 0 1 2 3 4
D. 编译失败
E. 一个异常在运行时被抛出


16. 如下代码:
public class Foo {
public static void main(String[] args) {
try {
return;
} finally {
System.out.println( "Finally" );
}
}
}
输出结果是什么?
A. Finally
B.编译失败
C. 代码正常运行但没有任何输出.
D. 运行时抛出异常


17. 如下代码:
class Base {
Base() { System.out.print("Base"); }
}
public class Alpha extends Base {
public static void main( String[] args ) {
new Alpha();
new Base();
}
}
结果是什么?
A. Base
B. BaseBase
C. 编译失败.
D. 代码运行但没有输出.
E. 运行时抛出异常.


18. 如下代码:
Float f = new Float("12");
switch (f) {
case 12: System.out.println("Twelve");
case 0: System.out.println("Zero");
default: System.out.println("Default");
}
结果是什么?
A. Zero
B. Twelve
C. Default
D. Twelve
Zero
Default
E. 编译失败.


19. 下面哪三个描述是正确的?
A. 默认构造器初始化方法变量
B. 默认构造器有和它所在类相同的访问修饰词.
C. 默认构造器调用其父类的无参构造器.
D. 如果一个类没有无参构造器,编译器会为它创建一个默认构造器.
E. 只有当一个类没有任何构造器时,编译器会为它创建一个默认构造器


20. 如下代码
10. public Object m() {
11. Object o = new Float(3.14F);
12. Object [] oa = new Object[1];
13. oa[0] = o;
14. o = null;
15. oa[0] = null;
16. print 'return 0';
17. }
当Float对象在第11行被创建后, 什么时候能够被垃圾回收?
A. 13行以后.
B. 14行以后.
C. 15行以后.
D. 16行以后
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics