第十二题:
11. class Alpha {
12. publicvoid foo() { System.out.print("Afoo "); }
13. }
14. public class Beta extends Alpha {
15. publicvoid foo() { System.out.print("Bfoo "); }
16. publicstatic void main(String[] args) {
17. Alpha a = new Beta();
18. Beta b = (Beta)a;
19. a.foo();
20. b.foo();
21. }
22. }
此程序的运行结果是?
A. Afoo Afoo
B. Afoo Bfoo
C. Bfoo Afoo
D. Bfoo Bfoo
E. 编译失败.
F. 运行时存在异常.
答案:D
知识点:
子类为父类对象实例化
向下转型,没什么绕弯的地方,不懂的去看相关内容
第十三题:
一下哪两个选项能够创建并初始化一个静态的整型数组:
A. static final int[] a ={ 100200 };
B. static final int[] a;
static { a=new int[2]; a[0]=100; a[1]=200;}
C. static final int[] a =new int[2]{ 100200 };
D. static final int[] a;
static void init() { a = new int[3];a[0]=100; a[1]=200; }
答案:A B
知识点:
这道题主要考的是静态成员变量的初始化方式,一共两种,一种是在声明的时候直接进行初始化,另外一种方式则是通过静态代码块进行初始化。
答案C中将new int[2]改为new int[]也是正确的。
第十四题:
10. interface Foo { intbar(); }
11. public class Sprite {
12. public int fubar( Foo foo ) { returnfoo.bar(); }
13. public void testFoo() {
14. fubar(
15. // insert code here
16. );
17. }
18. }
在第15行处插入哪段代码可以使得Sprite类完整?
A. Foo { public int bar(){ return 1; }
B. new Foo { public intbar() { return 1; }
C. new Foo() { public intbar() { return 1; }
D. new class Foo { publicint bar() { return 1; }
答案:C
知识点:
实例化接口时必须实现所有的抽象函数
第十五题
1. class Alligator {
2. public static void main(String[] args) {
3. int []x[] = {{12} {345} {6789}};
4. int [][]y = x;
5. System.out.println(y[2][1]);
6. }
7. }
以上程序的运行结果是?
A. 2
B. 3
C. 4
D. 6
E. 7
F. 编译失败
答案:E
二维数组,自己数一下就知道了
--------------------------------------------------------分割线-----------------------------------------------
本期问题:
第十六题:
当前目录是一个空目录,假设当前用户拥有对此目录读和写的权限,并执行如下代码
11. import java.io.*;
12. public class DOS {
13. public static void main(String[] args) {
14. File dir = new File("dir");
15. dir.mkdir();
16. File f1 = new File(dir "f1.txt");
17. try {
18. f1.createNewFile();
19. } catch (IOException e) { ; }
20. File newDir = new File("newDir");
21. dir.renameTo(newDir);
22. }
23. }
下列哪种情况是正确的?
A. 编译失败
B. 当前目录下创建了一个名为“dir”的空目录
C. 当前目录下创建了一个名为“newdir”的空目录
D. 当前目录下创建了一个名为“dir”的目录,在这个目录中包含了一个名为f1.txt的文件
E. 当前目录下创建了一个名为“newdir”的目录,在这个目录中包含了一个名为f1.txt的文件
第十七题:
11. class Converter {
12. public static void main(String[] args) {
13. Integer i = args[0];
14. int j = 12;
15. System.out.println("It is " + (j==i) + " that j==i.");
16. }
17. }
当程序员试图通过执行命令“java Converter 12”来编译并运行该程序时会出现哪种结果?
A. It is true that j==i.
B. It is false that j==i.
C. 抛出一个异常
D. 编译失败,因为第13行存在错误
第十八题:
11. String test = "Test A. Test B. Test C.";
12. // insert code here
13. String[] result = test.split(regex);
在第12行插入下列哪个正则表达式可以将test分割为 "Test A" "Test B" and "Test
C"?
A. String regex = "";
B. String regex = " ";
C. String regex = ".*";
D. String regex = "\\s";
E. String regex = "\\.\\s*";
F. String regex = "\\w[ \.] +";
第十九题:
5. import java.util.Date;
6. import java.text.DateFormat;
21. DateFormat df;
22. Date date = new Date();
23. // 此处插入代码
24. String s = df.format(date);
在第23行填入代码使得上述代码可以被编译通过
A. df = new DateFormat();
B. df = Date.getFormat();
C. df = date.getFormat();
D. df = DateFormat.getFormat();
E. df = DateFormat.getInstance();
第二十题
有一个名为Repetition的类:
1. package utils;
2
3. public class Repetition {
4. public static String twice(String s) { return s + s; }
5. }
又有另一个名为Demo的类
1. // 此处插入代码
2
3. public class Demo {
4. public static void main(String[] args) {
5. System.out.println(twice("pizza"));
6. }
7. }
在类Demo的第一行插入那条代码可以打印出pizzapizza?
A. import utils.*;
B. static import utils.*;
C. import utils.Repetition.*;
D. static import utils.Repetition.*;
E. import utils.Repetition.twice();
F. import static utils.Repetition.twice;
G. static import utils.Repetition.twice;
第二十题:
3. interface Animal { void makeNoise(); }
4. class Horse implements Animal {
5. Long weight = 1200L;
6. public void makeNoise() { System.out.println("whinny"); }
7. }
8. public class Icelandic extends Horse {
9. public void makeNoise() { System.out.println("vinny"); }
10. public static void main(String[] args) {
11. Icelandic i1 = new Icelandic();
12. Icelandic i2 = new Icelandic();
13. Icelandic i3 = new Icelandic();
14. i3 = i1; i1 = i2; i2 = null; i3 = i1;
15. }
16. }
当程序运行到第15行是,一共产生多少个可以被垃圾回收器回收的对象
A. 0
B. 1
C. 2
D. 3
E. 4
F. 6 作者: 杨_扬 时间: 2012-7-4 12:47
我发考题出来和大家分享,并且每期都给出上期的答案和知识点讲解
1,2,3期我都有技术分,挺欣慰的,付出了就有收获
这期为什么不给我分啊?请问作者: 蒋映辉 时间: 2012-7-5 06:54
嗯 对于没有给你第二次发加技术分的问题 深感抱歉 个人认为 如果每次发都加技术分 就成一个bug了 到时候每个人都搞一些比较好的题目发出来 过不了几天技术分就能满了 这样我觉得就完全失去了论坛督促学习的效果。
建议楼主不要抱着太大的功利心去泡论坛,学技术才是最关键的。 作者: 杨_扬 时间: 2012-7-5 08:10