Java二级选择题库

共 1934 道真题,覆盖公共基础知识与Java语言考点,支持错题记录。

题目示例

下列程序的输出结果是______。 public class Test { public static void main(String[] args){ int[] array={2,4,6,8,10}; int size=6; int result=-1; try { for(int i=0;i<size && result==-1;i++) if(array[i]==20) result=i; } catch(ArithmeticException e){ System.out.println("Catch---1"); } catch(ArrayIndexOutOfBoundsExce

  1. Catch---1
  2. Catch---2
  3. Catch---3
  4. 以上都不对

提供showDocument()方法,使Applet能够请求浏览器访问特定URL的类是______。

  1. Applet
  2. AppletContext
  3. JApplet
  4. URL

阅读下列代码 public class Test{ public static void main (String args[]){ System.out.println((2<0)?10:8); } } 其运行结果是______。

  1. 2
  2. 0
  3. 10
  4. 8

在使用interface声明一个接口时,用下面______修饰符修饰该接口时,该接口被使用的范围最广。

  1. private
  2. protected
  3. private protected
  4. public

若有语句String s="java",则查找s中字母a最后出现的位置的语句是______。

  1. s.lastIndexOf('a');
  2. charAt(2);
  3. s.indexOf('a');
  4. indexOf(s,'a');

若已有如下类定义: class Animal { } class Cat extends Animal { } class PetCat extends Cat { } 则下列语句中正确的是______。

  1. Cat cat=new Animal();
  2. PetCat cat=new Animal();
  3. Animal animal=new PetCat();
  4. PetCat cat=new Cat();

下列程序的运行结果是______。 public class MyTest{ public static void main (String[] args){ int i=0,j=0; for(j=1;j<100;j++){ i+=j; } System.out.println(j); } }

  1. 1
  2. 99
  3. 100
  4. 4950

阅读下列代码 public class Test2005 { public static void main(String args[]) { System.out.println(~(0xa5)&0xaa); } } 其运行结果是______。

  1. 0xa5
  2. 10
  3. 0x50
  4. 0xaa