A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

查找往期内容请访问
http://blog.csdn.net/crazybass81/article/category/1149502
大家可以回复本帖并留下你认为正确的答案,一起讨论,正确答案及解释我会在下期给出

上期答案
第六题
11. public class Person {
12.        privateString name;
13.        publicPerson(String name) {
14.                this.name = name;
15.        }
16.  public int hashCode() {
17.                return 420;
18.  }
19. }
下列哪个叙述是正确的:
A.在HashMap查找某个Person键值所需要的时间依赖于Map的大小。
B.执行删除一个Person键的操作,将删除HashMap中所有类型为Person的键
C.在HashSet中插入第二个Person对象,将导致第一个Person对象被移除。
D. 在HashSet中查找一个Person对象是否存在的时间是一个常数,不依赖于HashSet的大小
答案:A
知识点:
1.        假设某类集的大小为n,那么对此类集的查找算法的时间复杂度为O(n)因此A是正确的,且D是错误的。
2.        对于Set和Map中,对于“重复实例”的认定必须同时复写该类的equals()和hashCord()两个方法。否则对“重复实例”的认定只是比较对象实例的内存地址,因此B和C是错误的

第七题
5. import java.util.*;
6. public class SortOf {
7.       public static void main(String[] args) {
8.               ArrayList<Integer> a = newArrayList<Integer>();
9.               a.add(1); a.add(5); a.add(3);
11.            Collections.sort(a);
12.            a.add(2);
13.            Collections.reverse(a);
14.            System.out.println(a);
15.      }
16. }
该程序片段的运行结果是?
A. [1 2 3 5]
B. [2 1 35]
C. [2 5 31]
D. [5 3 21]
E. [1 3 52]
F. 编译失败
G. 运行时有异常抛出
答案:C
Conllections类定义了一系列针对容器操作的静态方法,笼统的讲凡事实现了Conlection接口的容器都可以在Conllections类中的静态方法中找到对应的操作,本题中使用到了其中的两个静态方法:
sort():根据元素的自然顺序对指定列表(List)按升序排列顺序。
reverse():反转指定列表中元素的顺序。
关于Conllections类的详细信息请参考JDK1.6的帮助文档
第八题
Given
11. public interface Status {
12.       /* 此处插入代码*/ int MY_VALUE = 10;
13. }
下列哪三个选项可以用于第12行
A. final
B. static
C. native
D. public
E. private
F. abstract
G. protected
答案:A B D
知识点:
接口的定义明确的要求接口要由:
抽象方法、全局常量 组成。
抽象方法的修饰词:public abstract
全局常量的修饰词:public final static

第九题
5. class Atom {
6.       Atom() { System.out.print("atom "); }
7. }
8. class Rock extends Atom {
9.       Rock(String type) { System.out.print(type); }
10. }
11. public class Mountain extends Rock {
12.       Mountain() {
13.               super("granite ");
14.               new Rock("granite ");
15.       }
16.       public static voidmain(String[] a){ newMountain(); }
17. }
上述代码片段的运行结果是?
A. 编译失败.
B. atom granite
C. granite granite
D. atom granite granite
E. An exception is thrown at runtime.
F. atom graniteatom granite
答案:F
知识点:
当子类被实例化的时候都要首先调用父类的构造方法,按照这个规则倒推,稍加细心,此题不难
第十题
10. class Line {
11.       public class Point { public int x, y;}
12.       public Point getPoint() { return new Point(); }
13. }
14. class Triangle {
15.       public Triangle() {
16.                // 此处插入代码
17.       }
18. }
在16行处插入代码获得一个Class Point的实例?
A. Point p = Line.getPoint();
B. Line.Point p = Line.getPoint();
C. Point p = (new Line()).getPoint();
D. Line.Point p = (newLine()).getPoint();
答案:D
知识点:
创建实例内部类的实例时,外部类的实例必须存在
外部类类名.内部类类名 引用变量名称 = 外部类对象的引用.new 内部类构造器;
外部类类名.内部类类名 引用变量名称 = new 外部类构造器.new 内部类构造器;
另一种可能的正确答案
Line.Point p = new Line().new Point();

--------------------------------------------------------分割线-----------------------------------------------

本期问题:
第十二题:
11. class Alpha {
12.         public void foo() { System.out.print("Afoo "); }
13. }
14. public class Beta extends Alpha {
15.         public void foo() { System.out.print("Bfoo "); }
16.         public static 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. 运行时存在异常.

第十三题:
一下哪两个选项能够创建并初始化一个静态的整型数组:
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; }

第十四题:
10. interface Foo { int bar(); }
11. public class Sprite {
12.                 public int fubar( Foo foo ) { return foo.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 int bar() { return 1; }
C. new Foo() { public int bar() { return 1; }
D. new class Foo { public int bar() { return 1; }

第十五题
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. 编译失败

评分

参与人数 2技术分 +1 黑马币 +30 收起 理由
职业规划-刘倩老师 + 30 赞一个!
蒋映辉 + 1 楼主辛苦了

查看全部评分

14 个回复

倒序浏览
12d 13ac 14a 15e不知道有没有对的{:soso_e110:}看完这十二期也没戏了{:soso_e109:}
回复 使用道具 举报
黑马-李勇 发表于 2012-7-3 03:26
12d 13ac 14a 15e不知道有没有对的看完这十二期也没戏了

两对两错
回复 使用道具 举报
我感觉 是 12 d  13  a  14  c   15  e
回复 使用道具 举报
第十二题:
11. class Alpha {
12.         public void foo() { System.out.print("Afoo "); }
13. }
14. public class Beta extends Alpha {
15.         public void foo() { System.out.print("Bfoo "); }
16.         public static 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; }
答:AC
第十四题:
10. interface Foo { int bar(); }
11. public class Sprite {
12.                 public int fubar( Foo foo ) { return foo.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 int bar() { return 1; }
C. new Foo() { public int bar() { return 1; }
D. new class Foo { public int 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

以上为个人答案,期待Lz 公布答案。
回复 使用道具 举报
万宝东 发表于 2012-7-3 07:38
我感觉 是 12 d  13  a  14  c   15  e

对俩错俩
回复 使用道具 举报
万宝东 发表于 2012-7-3 07:38
我感觉 是 12 d  13  a  14  c   15  e

抱歉,看错了,你对了三个错了一个
回复 使用道具 举报
陈淑飞 发表于 2012-7-3 08:13
第十二题:
11. class Alpha {
12.         public void foo() { System.out.print("Afoo "); }

对三错一

点评

绝对不可能。 我认为15题考的int []x[]定义二维数组合法性及y[2][1]是否存在此元素。 而不是仅仅考,数组初始化时没有用,号分隔元素。 所以15题答E。  发表于 2012-7-3 08:38
回复 使用道具 举报
这期是我的失误,只发了四道题,补上一道吧,算作第11题

22. StringBuilder sb1 = new StringBuilder("123");
23. String s1 = "123";
24. // 此处插入代码
25. System.out.println(sb1 + " " + s1);
将下列哪段代码插入到第24行处可以使输出结果为"123abc 123abc"?
A. sb1.append("abc"); s1.append("abc");
B. sb1.append("abc"); s1.concat("abc");
C. sb1.concat("abc"); s1.append("abc");
D. sb1.concat("abc"); s1.concat("abc");
E. sb1.append("abc"); s1 = s1.concat("abc");
F. sb1.concat("abc"); s1 = s1.concat("abc");
G. sb1.append("abc"); s1 = s1 + s1.concat("abc");
H. sb1.concat("abc"); s1 = s1 + s1.concat("abc");
回复 使用道具 举报
陈淑飞 发表于 2012-7-3 08:13
第十二题:
11. class Alpha {
12.         public void foo() { System.out.print("Afoo "); }

我没说你最后一题错,我是说你的答案中三个对一个错

点评

你直接告诉我答案吧,因为十二到十四题,我都验证过,都没有错呢。  发表于 2012-7-3 08:54
回复 使用道具 举报
本帖最后由 杨_扬 于 2012-7-3 09:27 编辑
陈淑飞 发表于 2012-7-3 08:13
第十二题:
11. class Alpha {
12.         public void foo() { System.out.print("Afoo "); }

好,我告诉你,第13题的答案是AB
回复 使用道具 举报
杨_扬 发表于 2012-7-3 09:15
好,我告诉你,第13题的答案是AB


不对吧,十四题,测试如下:
   interface Foo { int bar(); }
public class Sprite {
                 public int fubar( Foo foo ) { return foo.bar(); }
                 public void testFoo() {
                      int i = fubar(
                                 // insert code here
    new Foo() { public int bar() { return 1; } }  // 答C 没错
                                /* fubar方法要求一个实现Foo接口的对象,但A的写法显示不是一个对象 */
    /* Foo { public int bar() { return 1; } }  //答案A 显然也是错的 */
    /* 没见过java语法new后面不是接()或者是[]的。 */
    /* new Foo { public int bar() { return 1; }  //答案B 显然也是错的 */


                                );
   System.out.println("看看结果:"+i);
                 }
  public static void main(String[] args){
   Sprite s = new Sprite();
   s.testFoo() ;
  }
}

答C 执行结果如下:


回复 使用道具 举报
陈淑飞 发表于 2012-7-3 09:31
不对吧,十四题,测试如下:
   interface Foo { int bar(); }
public class Sprite {

抱歉,是13题,我打字的时候笔误,13题的答案是AB
回复 使用道具 举报
不好意思,看错了,把十三题看到了十四题,我再看看十三题
回复 使用道具 举报
杨_扬 发表于 2012-7-3 09:32
抱歉,是13题,我打字的时候笔误,13题的答案是AB

呵呵,拜服。
知道错在哪了,呵呵。学习了,谢谢楼主。
关于数组的初始化,还没有掌握 牢固啊。呵呵。
数组初始化一般分为三种:
1. 静态初始化  在定义时就会数组分配内存空间和赋值
   如1.1   int[] a = = { 100200 };
        1.2    int[] a = new int[]{100200};
    注:像 int[] a = new int[2]{100200,1};
         这样的会编译是报错,因为既然已经初始化了,就不应该再给数组定义维度信息了。也算是编译器的一种优化吧,怕程序员写的维度信息与初始化元素个数不相符。

    答案C  static final int[] a = new int[2]{ 100200 };
      那就错啦,呵呵我还以为 编译器会判断出a定义了二个元素数组,会自动给a[1]赋值0呢。  
2. 动态初始化  分配内存和赋值分开
   String books[] = new String[2];   
       books[0] = "a";   
       books[1] = "b";
3. 默认初始化
   int[] a = new [2];
...
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马