java笔试错题记录

1.有关静态初始化块说法正确的是?

正确答案: A B C 你的答案: B C (错误)
A无法直接调用静态初始化块
B在创建第一个实例前或引用任何静态成员之前,将自动调用静态初始化块来初始化
C静态初始化块既没有访问修饰符,也没有参数
在程序中,用户可以控制何时执行静态初始化块

2. 以下代码输出结果为?

public class Test {
    public static void main(String[] args) {
        System.out.println(test());

    }
    private static int test() {
        int temp = 1;
        try {
            System.out.println(temp);
            return ++temp;
        } catch (Exception e) {
            System.out.println(temp);
            return ++temp;
        } finally {
            ++temp;
            System.out.println(temp);
        }
    }
}

以下代码输出的结果?

答案:
catchNum------10
15


 public static int val() {
        int num = 5;
        try {
            num = num / 0;
        } catch (Exception e) {
            num = 10;
            System.out.println("catchNum------"+num);
        } finally {
            num = 15;
        }
        return num;
    }


3 java的基本编程单元是类,基本存储单元是变量。

4. 下面哪种情况会导致持久区jvm堆内存溢出?

正确答案: C 你的答案: D (错误)
A循环上万次的字符串处理
B在一段代码内申请上百M甚至上G的内存
C使用CGLib技术直接操作字节码运行,生成大量的动态类
D不断创建对象

5.Which statement declares a variable a which is suitable for referring to an array of 50 string objects?下面哪个Java语句声明了一个适合于创建50个字符串对象数组的变量?

正确答案: B C F 你的答案: A C D E (错误)
A char a[][];
B String a[];
C String[] a;
D Object a[50];
E String a[50];
F Object a[];

6.下列哪些操作会使线程释放锁资源?

正确答案: B C 你的答案: B D (错误)
A sleep()
B wait()
C join()
D yield()

7.protected访问权限要小于包访问权限。( )

正确答案: B 你的答案: A (错误)
正确
错误

8. Thread. sleep()是否会抛出checked exception?

解析: Thread.sleep() 和 Object.wait(),都可以抛出 InterruptedException。这个异常是不能忽略的,因为它是一个检查异常(checked exception)
正确答案: A 你的答案: B (错误)
A 会
B 不会

9. 假定Base b = new Derived(); 调用执行b.methodOne()后,输出结果是什么?

public class Base
{
   public void methodOne()
   {
      System.out.print("A");
      methodTwo();
   }

   public void methodTwo()
   {
      System.out.print("B");
   }
}

public class Derived extends Base
{
   public void methodOne()
   {
      super.methodOne();
      System.out.print("C");
   }

   public void methodTwo()
   {
      super.methodTwo();
      System.out.print("D");
   }
}

正确答案: A 你的答案: D (错误)
ABDC
AB
ABCD
ABC

10.list是一个ArrayList的对象,哪个选项的代码填到//todo delete处,可以在Iterator遍历的过程中正确并安全的删除一个list中保存的对象?()

Iterator it = list.iterator();
int index = 0;
while (it.hasNext())
{
    Object obj = it.next();
    if (needDelete(obj))  //needDelete返回boolean,决定是否要删除
    {
        //todo delete
    }
    index ++;
}

正确答案: A 你的答案: B (错误)
it.remove();
list.remove(obj);
list.remove(index);
list.remove(obj,index);
屏蔽本题
添加笔记
收藏
分享
解析
A
Iterator 支持从源集合中安全地删除对象,只需在 Iterator 上调用 remove() 即可。这样做的好处是可以避免 ConcurrentModifiedException ,当打开 Iterator 迭代集合时,同时又在对集合进行修改。有些集合不允许在迭代时删除或添加元素,但是调用 Iterator 的remove() 方法是个安全的做法。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

有时间指导毕业设计

觉得写的好的话可以给我打赏

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值