为了正常的体验网站,请在浏览器设置里面开启Javascript功能!

第3部分SCJP认证试题-沈阳师范大学

2017-09-27 50页 doc 169KB 40阅读

用户头像

is_321635

暂无简介

举报
第3部分SCJP认证试题-沈阳师范大学第3部分SCJP认证试题-沈阳师范大学 沈阳师范大学软件学院 OFTWARE COLLEGE OF SHENYANG NORMAL UNIVERSITY S ,第三版, 宋波 李晋 李妙妍 张艳丽 编写 姓名, 学号, 年级, 专业, 沈阳师范大学软件学院&软件工程系 前 言 本书是一本课后课后习题、SCJP试题的指导性教材~与《Java语言程序设计》,自编教材,配套使用。编写目的是通过一系列的上机实验与课后练习使学生理解并掌握所学的知识。作为一本教辅用书~希望读者把本书作为掌握知识的一个工具和桥梁~从而达到...
第3部分SCJP认证试题-沈阳师范大学
第3部分SCJP认证试题-沈阳师范大学 沈阳师范大学软件学院 OFTWARE COLLEGE OF SHENYANG NORMAL UNIVERSITY S ,第三版, 宋波 李晋 李妙妍 张艳丽 编写 姓名, 学号, 年级, 专业, 沈阳师范大学软件学院&软件工程系 前 言 本书是一本课后课后习题、SCJP试题的指导性~与《Java语言程序》,自编教材,配套使用。编写目的是通过一系列的上机实验与课后练习使学生理解并掌握所学的知识。作为一本教辅用书~希望读者把本书作为掌握知识的一个工具和桥梁~从而达到对Java语言语法和的深入理解~提高读者的程序设计能力~并在学习的过程中不断发现问题、思考问题、解决问题。 本书共由二部分组成。第一部分为针对教材每一章的练习题~读者可以进行自测并掌握每一章的重点。第二部分为Java国际认证,SCJP,典型试题~通过集中练习~可以使读者较快地掌握SCJP认证的内容~为顺利过关作好准备。 本书作为“软件学院重点课程建设”建设成果的一部分~由软件工程系的宋波老师组织编写~参加编写工作的有李晋、李妙妍和张燕丽等老师。本书的编写工作~自始至终得到软件学院的领导和软件工程系的大力支持~周传生教授和李航副教授对于本书的编写提出了宝贵的建议~本书也吸纳和借鉴了中外参考文献中的知识原理和资料~在此一并致以谢忱。 编者 2010年7月 目 录 第1部分:习题 ......................................................... 错误~未定义书签。 第1章:绪论 ...........................................................................................错误~未定义书签。 第2章:Java语言基础............................................................................................................. 1 第3章:Java面向对象特性..................................................................................................... 4 第4章:Java高级特征........................................................................................................... 11 第5章:异常处理 ................................................................................................................... 13 第6章:Java输入/输出.......................................................................................................... 16 第7章:AWT及AWT事件处理.......................................................................................... 18 第8章:Applet基础编程 ....................................................................................................... 21 第9章:Java多线程............................................................................................................... 22 第10章:Java网络程序设计................................................................................................. 23 第11章:JDBC技术 .............................................................................................................. 23 第2部分:SCJP认证试题....................................................................... 24 试题,: ................................................................................................................................... 24 : .................................................................................................................................... 36 试题2 第2章:Java语言基础 1. 已知“int i=33”,则指出下列的表达式哪一个是不正确的( )。 A byte b = i B long m = i C double d = 3.14+i D int n = ++i 2(已知有下列声明语句“int i, j; float x, y; double u, v;”,则下列哪个赋值是合法的( )。 A i = x; B x=u+y; C x=7.8+j*y; D v=3.4+i*u; 3. 当执行以下程序片段后:“int i=1;int fox[]=new fox[3];int x=fox[i];x=x+i;”,x的值 为 。 4. 下面代码的输出结果为( )。 public class Sun { public static void main(String args[]) { int j=0; for (int i=0; i<10; i++) { j=i*10+6; if (j%3!=0) { continue; } System.out.println( j ); } } } 5. 指出下列的表达式哪一个是正确的( )。 A boolean b=0 B float f=3.1415 C byte a=128 D int d=288 6. 假如“boolean a=true;int b=2,c=6”,则表达式a&&(b++%2==0)的值为 ,c+=c--/++b 的值为 。 7. 下面代码的输出结果为( )。 public class ForDemo { public static void main(String args[]) { outer: for(int i=1; i<3; i++) { inner: for(int j=1; j<3;j++) { if(j= =2) continue outer; System.out.println(“i=”+i+“j=”+j); } } } 1 } 8. 假设“int x=10,y=20, z=30”,在表达式a=x>y?x:y-2中a的值 为 ,!(x6) break inner; } } System.out.println("sum="+sum); 2 } } 14. 下面程序是用do-while语句计算10的阶乘。请在每条横线处填写一个语句,使程序的功能完整。 注意:请勿改动main()主方法和其它已有的语句内容,仅在横线处填入适当的语句。 public class J_Test{ public static void main( ){ int n=10; long result=1; do{ } System.out.println("10的阶乘为:"+result); } } 15. 设x=1,y=2,z=3,则表达式y+=z--/++x的值为( )。 A(3 B(3.5 C(4 D(5 16. 下列程序运行后,输出的结果是( )。 public class Test5{ public static void main(String[] args){ outer: for(int i=0;i<3;i++){ inner: for(int j=0;j<2;j++){ if(j==1) continue outer; System.out.println(i+“and”+j); } } } } A(0 and 0 B(0 and 1 C(1 and 0 D(0 and 0 1 and 0 0 and 1 1 and 1 1 and 1 2 and 0 0 and 2 1 and 2 2 and 2 17. 下列数组定义及赋值,错误的是( )。 A(int a[]={1,2,3,4,5}; B(int intArray[]; C(int intArray[]=new int[3]; intArray[1]=1; intArray[2]=2; 3 intArray[3]=3; D(int a[][]=new int[2][]; a[0]=new int[3]; a[1]=new int[4]; 18. 下列程序执行以后,输出结果为( )。 public class Exam01 { public static void main(String[ ] args) { int x=5; int y=2; float m=2.5f; m=m<=x%y?x-m:y-m; System.out.println(m); } } A(-0.5 B(-2.5 C(2.5 D(0.5 第3章:Java面向对象特性 1(下列关于变量作用域的描述中,不正确的一项是( )。 A(变量属性是用来描述变量作用域的。 B(局部变量作用域只能是它所在的方法的代码段。 C(类变量能在类的方法中声明。 D(类变量的作用域是整个类。 下面代码的输出结果为( )。 2( class Parent { void printMe( ) { System.out.println("parent"); } } class Child extends Parent { void printMe( ) { System.out.println("child"); } void printAll( ) { super.printMe(); printMe(); } } public class TestThis { 4 public static void main (String args[ ]) { Child myC=new Child( ); myC.printAll(); } } 3(下列程序在编译以后,哪一行将引起一个编译时错误,( ) 1) public class Exam02 { 2) int m, n; 3) public Exam02() { } 4) public Exam02(int a) { 5) m=a; 6) } 7) public static void main(String arg[ ]) { 8) Exam02 t1,t2; 9) int j,k; 10) j=0; 11) k=0; 12) t1=new Exam02(); 13) t2=new Exam02(j,k); 14) } 15) } A(line 3 B(line 7 C(line 8 D(line 13 4(下面代码的输出结果为( )。 class Father { private int f1, f2; public Father(int x, int y) { f1=x; f2=y; } public Father(int x) { this(x, 0); } public void display( ) { System.out.println(“f1=”+f1+“f2=”+f2); } } class Son extends Father { private int s1, s2; 5 public Son(int x, int y, int z) { super(x); s1=y; s2=z; } public void display( ) { super.display( ); System.out.println(“s1=”+s1+“s2=”+s2); } } public class Test { public static void main (String args[]) { Father f=new Son( 5, 6, 7); f.display( ); } } 5(下面关于构造方法的说法哪个选项是正确的( )。 A 构造方法不能被重载 B 构造方法不能被继承 C 构造方法可以返回一个对象的引用 D 构造方法可以直接利用对象名调用 6( 关键词用来引用父类中的成员变量和方法, 关键词用来指向当前对象自身。 7(下面代码的输出结果为( )。 class A { public void prt ( ) { System.out.println(“1”); } public A ( ) { System.out.println(“A”); } } public class B extends A { public void prt ( ) { super.prt ( ); System.out.println(“2”); } public B ( ) { System.out.println(“B”); } public static void main(String args[]) { 6 A a=new B( ); a.prt ( ); } } 8(下面代码的输出结果为( )。 public class Person { String name; int age; String sex; public Person(String name, int age, String sex) { this.name=name; this.age=age; this.sex=sex; } public Person(String name, int age) { this (name, age, “male”); } public Person(String name) { this (name, 30); } public static void main (String args[]) { Person p1=new Person (“Tom”, 18); Person p2=new Person (“John”); System.out.println(p1.name+“-”+p1.age+“-”+p1.sex); System.out.println(p2.name+“-”+p2.age+“-”+p2.sex); } } 9(在子类中重写父类的方法只需要满足相同的方法名和参数列表即可。( ) 10(在一个类中可以定义同名的多个方法,它们之间的区别在于参数列表不同,这种叫做方法的 。如果父类中原有的方法不能满足子类的要求,可以在子类中对父类的方法重新编写代码,这叫做方法的 。 11(一个构造方法可以返回一个对象的引用,即返回值类型是引用类型。 ( ) 12(下面代码的输出结果为( )。 class OverloadDemo { void test ( ) { System.out.println(“No parameters”); } 7 void test (int a, int b ) { System.out.println(“a and b: ”+a+“and”+b); } void test (double a ) { System.out.println(“Inside test double a: ”+a); } } public class Overload { public static void main(String args[]) { OverloadDemo ob=new OverloadDemo( ); ob.test ( ); ob.test(10,20); ob.test(123.2); } } 13(下面代码的输出结果为( )。 class Graphix { void calArea( ) { System.out.println(“求图形面积”); } } class Rect extends Graphix { void calArea( ) { System.out.println(“求长方形面积”); } } class Circle extends Graphix { void calArea( ) { System.out.println(“求圆面积”); } } public class Test { public static void main (String args[]) { Graphix gc=new Rect( ); gc.calArea( ); gc=new Circle( ); gc.calArea( ); } } 14(在下列关于方法的重载和覆盖的描述中,错误的是( )。 A 方法重载是指在同一个类中允许出现方法参数个数、顺序不同而方法名相同的若干方法 8 B 方法覆盖是指在父类和子类之间出现的方法头相同而方法体不同的多个方法 C 方法重载是在编译时进行选择的 D 方法覆盖是在编译时进行选择的 15(下列代码的输出结果是___________。 public class Oct{ public static void main(String argv[]){ Oct o=new Oct(); o.amethod(); } public void amethod(){ int oi=012; System.out.println(oi); } 16(在下列代码中第___________行将产生编译错误。 1: class Example{ 2: String str; 3: public Example(){ 4: str="example"; 5: } 6: public Example(String s){ 7: str=s; 8: } 9: } 10:class Demo extends Example{ 11:} 12:public class Oct{ 13: public void f(){ 14: Example ex=new Example("Good"); 15: Demo d=new Demo("good"); 16: } 17:} 17(构造方法一般不允许有任何返回值,因此需要在返回类型处标注为void。( ) 18(下面代码的输出结果为( )。 class J_Base{ public void mb_method(){ System.out.println("Base"); } } 9 public class J_Test extends J_Base{ public void mb_method(){ System.out.println("Test"); } public static void main(String args[]){ Object a=new J_Test(); ((J_Base)a).mb_method(); } } 19. 下面代码的输出结果为( )。 public class InheritTest1{ public static void main(String args[]){ A aa = new A(); B bb = new B(); aa.show(); bb.show(); } } public class A{ = 1; int a double d = 2.0; void show(){ System.out.println("Class A: " + "\ta=" + a + "\td=" + d); } } public class B extends A{ float a = 3.0f; String d = "Java program."; int b = 4; void show(){ System.out.println("Class A: " + "\ta=" + super.a + "\td=" + super.d); super.show(); System.out.println("Class B: " + "\ta=" + a + "\td=" + d + "\tb=" + b); } } 10 第4章:Java高级特征 1(如果一个方法只有方法的声明,而没有方法的实现,则成为 方法。该方法通过关键字 来定义。 2(类的声明“public class TestJava extends BaseJava implements Runable{ }”中,定义的类名 是 ,其父类是 ,实现了 接口。含有这个类的源程序必须保 存为 (写出包括扩展名的文件名)。 3(下面是类的定义,将程序补充完整。 class A{ String s; int a=66; A(String s1){ s=s1; } static int geta(){ return a; } } public class { int x,y; MyClass(int i, ){ x=i; y=j; } } 4(请在下面程序的划线处填上适当的语句,使程序能正常运行。 class X{ abstract void callme(); void metoo(){ System.out.println("metoo()方法"); } } class Y X{ void callme(){ System.out.println("重写的callme()方法"); } } 5(当你编译和运行下列的代码时,会出现下面选项中的哪种情况( )。 11 public class Pvf { static boolean Paddy; public static void main(String[ ] args) { System.out.println(Paddy); }} A 编译时错误 B 编译通过并输出结果false C 编译通过并输出结果true D 编译通过并输出结果null 6(欲构造ArrayList类的一个实例,此类继承了List接口,下列哪个方法是正确的( )。 A ArrayList myList=new Object(); B ArrayList myList=new List(); C List myList=new ArrayList(); D List myList=new List(); 7(interface Printable { void print( ) { }; } 上述接口的定义是正确的。 ( ) 8(Java语言中同一包(package)中的类不能同名,否则会产生命名冲突。( ) 9(在类的定义中使用权限修饰符来保护类的变量和方法,其中类中带有private的成员只能被这个类自身访问。 ( ) 10(下列哪个类的声明使得该类不能再派生子类( )。 A static class FooBar { } B abstract class FooBar { } C public class FooBar { } D final class FooBar { } 11(一个非抽象类要实现某个接口,就必须实现该接口中的所有抽象方法。( ) 12(下面代码的输出结果为( )。 public class TestEquals { public static void main(String args[]) { String s1=new String(“Hello World!”); String s2=new String(“Hello World!”); if(s1= =s2) { System.out.println(“s1= = s2”); } else { System.out.println(“s1!=s2”); } if(s1.equals(s2)) { System.out.println(“s1 is equal to s2”); }else { System.out.println(“s1 is not equal to s2”); } } } 13(在类的修饰符中,规定只能被同一包类所使用的修饰符是( )。 A public B 默认 C final D abstract 12 14(Java语言中,定义子类时,使用关键字___________来给出父类名。如果没有指出父类,则该类的默认父类为___________类。 15(接口中所定义的常量具有___________和___________的属性,而其方法具有public和___________ 属性。 16(顶层类的访问控制修饰符为___________和___________。 17(下面代码的输出结果为( )。 class J_Class{ static int m_data=0; } class J_Test{ public static void main(String args[]){ J_Class a=new J_Class(); J_Class b=new J_Class(); a.m_data=1; b.m_data=2; System.out.println(a.m_data); } } 18(用整型数10创建一个Integer类的对象,下列语句中能完成上述功能的一个是( )。 A(Integer i=new Integer(10); B(Integer i=10; C(int i=10; D(Integer i=Integer(10); 19(运行下列代码将产生编译错误: public class Person{ static int arr[] = new int[10]; public static void main(String a[]) { System.out.println(arr[1]); } } 第5章:异常处理 1( 如果下列代码在调用oneMethod( )时一定会产生某个异常对象,则哪一条语句肯定不会显示出来 ( )。 public void test( ) { try { oneMethod( ); //调用方法oneMethod( ) 13 System.out.println( “condition 1”); } catch (ArrayIndexOutOfBoundsException e) { System.out.println(“condition 2”); } catch(Exception e) { System.out.println(“condition 3”); } finally { System.out.println(“finally”); } } A condition 1 B condition 2 C condition 3 D finally 2(在 Java的异常处理语句try-catch-finally中, 语句后面是可能产生异常的代码, 语句后面是捕获到某种异常对象时进行处理的代码, 语句后面是无论是否捕获到异常 都必须执行的代码。 3(下面代码的输出结果为( )。 public class TestException { public static void main (String args[]) { String friends[ ]={“Lisa”, “Bily”}; try { for(int i=0; i<4; i++) { System.out.println(friends[i]); } }catch(ArrayIndexOutOfBoundsException e) { System.out.println(“index err”); } System.out.println(“This is the end”); } } 4(设下列try-catch语句块中的第二个语句s2将引起一个异常,那么以下哪段代码肯定不会被执行( )。 try { s1; s2; s3; }catch (Exception e1) { } finally {s4;} A s1 B s2 C s3 D s4 5(异常处理具体有两种方式: 和 。 6(下面代码的输出结果为( )。 14 public class TestException { public static void main (String args[]) { int i=0, num=0; int s[]={2,4,6}; try { while(i<4) { num+=s[i]; i++; } System.out.println(“Normal ended.”); }catch(Exception e) { System.out.println(“index err”); }finally { System.out.println(“this is an end”); } } } 7(在方法中声明将产生的异常抛出使用的关键词是throw 。( ) 8(下列关于异常处理的描述中,错误的是( )。 A 程序运行时出现的异常是通过系统默认的异常处理程序进行处理的 B 在程序中可以使用try-catch语句捕捉异常和处理异常事件 C 对于捕获的异常只能在当前方法中处理 D 使用throw语句可将异常抛出到调用当前方法的方法中处理 9(下面代码的输出结果为( )。 public class J_Example{ public static void main(String args[]){ try{ try{ int i=1/0; } catch(Exception e){ System.out.print("1");} finally{ System.out.print("2");} } catch(Exception e){ System.out.print("3"); } 15 finally{ System.out.print("4");} System.out.print("5\n"); } } 10(下面代码的输出结果为( )。 class ExcepTest{ public static void main(String args[]){ try{ method(); }catch(Exception e){ System.out.println('m'); } System.out.println('n'); } static void method(){ try{ wrench(); System.out.println("a"); }catch(ArithmeticException e){ System.out.println("b"); }finally{ System.out.println("c"); } System.out.println("d"); } static void wrench(){ throw new NullPointerException(); } } 第6章:Java输入/输出 1(对于java.io包中的所有I/O类,根据数据流所关联的是数据源还是其他数据流,可分为( ) 和( )。 2(下列程序的功能是读取并输出指定文件ReadFile.java的内容。在划线处加入适当代码,使程序能够 正常运行。 1: import java.io.*; 2: public class ReadFile { 16 3: public static void main (String args[] ) { 4: File f=new File(“ReadFile.java”); 5: try { 6: FileReader fr= ; //创建一个从文件f读取数据的文件输入流fr 7: BufferedReader br= ; //创建一个缓存输入流,套接文件流fr 8: String s=br.readLine( ) ; 9: while(s!=null) { 10: ; //在屏幕上显示出字符串str 11: s=br.readLine( ); 12: } 13: fr.close( ); 14: br.close( ); 15: }catch(IOException e) { 16: System.out.println(e.getMessage( )); } 17: } 18: } 3(下列哪条语句可以正确创建出一个BufferedReader数据流( )。 A new BufferedReader(new FileReader(“myFile.txt”)); B new BufferedReader(new FileInputStream(“myFile.txt”)); C new BufferedReader(new DataInputStream(“myFile.txt”)); D new BufferedReader(“myFile.txt”); 4(Java在System类中定义了与系统输入/输出相联系的三个流,他们是( )、( )和( )。 5(在Java的输入/输出中,节点流与过滤流的主要的区别在于处理的流的方向不同。( ) 6(InputStream类是输入流类,它是所有字符输入流类的父类。 ( ) 7(下列程序实现了从键盘输入字符串,将该字符串存入String类的对象str中,并在屏幕上显示出该字符串。在划线处加入适当代码,使程序能够正常运行。 1: import java.io.*; 2: public class Demo { 3: public static void main (String args[] ) { 4: InputStreamReader isr= ; 5: BufferedReader br=new BufferedReader(isr); 6: try { 7: String str = ; //将br读入的一行字符串存入str 8: ; //在屏幕上显示出字符串str 17 9: }catch(IOException e) { 10: System.out.println(e.getMessage( )); 11: } 12: } 13: } 8(要调用类java.io.InputStream的read或close方法,就必须处理异常,该异常的具体类型是___________。 9(在I/O流FileInputStream、BufferedInputStream、DataInputStream和ByteArrayInputStream中,节点流的个数是___________。 第7章:AWT及AWT事件处理 1(下述哪个方法可以将MenuBar加入到Frame中( )。 A setMenu( ) B setMenuBar( ) C add( ) D addMenuBar( ) 2(在java.awt包中, 类是一个容器,可以容纳其他组件和容器,但它却不能独立存在。 下面程序的运行结果为( )(注意:本题请画出运行结果,可以文字描述来作辅助说明。) 3( import java.awt.*; public class GridLayoutWindow { public static void main (String args[]) { Frame f=new Frame(“GridLayout Example”); f.setLayout(new GridLayout(2,3 )); Button b1=new Button(“B1”); Button b2=new Button(“B2”); Button b3=new Button(“B3”); Button b4=new Button(“B4”); Button b5=new Button(“B5”); Button b6=new Button(“B6”); f.add(b1); f.add(b2); f.add(b3); f.add(b4); f.add(b5); f.add(b6); f.pack( ); f.setVisible(true); } } 18 4(编写程序。如图所示,窗口Frame是流式布局管理器,标题为“Test”,当用户每次鼠标单击“Start”按钮时,程序都会在屏幕上的DOS窗口中输出一行字符串“单击成功!”。 5(java.awt包中主要包括三个概念,它们是组件、 和 。 6(下面程序的运行结果为( )(注意:本题请画出运行结果,可以文字描述来作辅助说明。) import java.awt.*; public class GridLayoutWindow { public static void main (String args[]) { Frame f=new Frame(“GridLayout Example”); f.setLayout(new GridLayout(2,2)); Label b1=new Label(“Label1”); Button b2=new Button(“Button1”); Label b3=new Label(“Label2”); Button b4=new Button(“Button2”); f.add(b1); f.add(b2); f.add(b3); f.add(b4); f.pack( ); f.setVisible(true); } } 7(下面是一个单击按钮事件响应的,其运行效果为:用户每次鼠标单击“Press Me”按钮时,程序都会在DOS命令窗口中输出一行字符串“a button has been pressed”。请在划线处填写语句,完成此程序,使它能正确执行。 1: import java.awt.*; 2: import ; 3: public class TestActionEvent { 4: public static void main (String args[] ) { 5: Frame f=new Frame(“Test”); 6: Button b=new Button(“Press Me”); //创建一个按钮,标签为Press Me 7: Monitor bh=new Monitor( ); //创建一个监听器类实例bh 19 8: b. ; //为按钮b注册监听器 9: f.pack( ); 10: f.setVisible(true); 11: } 12: } 13: class Monitor { //定义监听器类,实现监听器接 口 14: public static void main (String args[]) { 15: public void actionPerformed(ActionEvent e) { 16: System.out.println(“a button has been pressed”); 17: } 18: } 19: } 8(AWT事件处理模型中主要包含三类对象:事件、事件源和事件处理器。( ) 9(下面哪条语句是使用网格布局管理器将一个Frame的实例frm分成1行3列( )。 A frm.setLayout(new GridLayout(1,3)); B frm.setLayout(new GridLayout(3,1)); C frm.setLayout(new GridLayout(3)); D frm.setLayout(new GridLayout(1)); 10(默认情况下,Applet使用流式布局管理器(FlowLayout)。 ( ) 11(下面程序的运行结果为( )(注意:本题请画出运行结果,可以文字描述来作辅助说明。) import java.awt.*; public class FlowLayoutWindow { public static void main (String args[]) { Frame f=new Frame(“FlowLayout Example”); f.setLayout(new FlowLayout( )); Button b1=new Button(“OK”); Button b2=new Button(“OPEN”); Button b3=new Button(“CLOSE”); f.add(b1); f.add(b2); f.add(b3); f.setSize(100, 100 ); f.setVisible(true); } } 12(在AWT中,所有GUI标准组件类的父类是( )。 A Button B List C Component D Container 13(在下列容器中最简单的无边框的又不能移动和缩放的只能包含在另一种容器中的容器是( )。 A Window B Dialog C Frame D Panel 14( 所有事件类的父类是( )。 A ActionEvent B AwtEvent C KeyEvent D MouseEvent 20 15(在AWT中,每种类型的事件都定义了相应的事件处理接口,即___________。委托方式事件处理机制的实现包括______________________和______________________。 16(下面程序的运行结果为( )(注意:本题请画出运行结果。) import java.awt.*; public class FrTest{ public static void main(String args[]){ new FrameOut(); } } class FrameOut extends Frame{ Button btn1, btn2, btn3; FrameOut(){ super("Buttons"); setLayout(new FlowLayout()); btn1 = new Button("B1"); add(btn1); btn2 = new Button("B2"); add(btn2); btn3 = new Button("B3"); add(btn3); setSize(300,200); setVisible(true); } } 17(FlowLayout是 和 的默认布局管理器。 第8章:Applet基础编程 1(Applet的生命周期包括Applet的 、 和 几个状态。 2(下列哪个方法与Applet的显示无关( )。 A draw( ) B paint( ) C repaint( ) D update( ) 3(在Applet的生命周期中,当打开浏览器窗口时,系统会首先自动调用 方法;而当用 户离开当前窗口时,系统会自动调用 方法。 4(下面是在浏览器中显示“Hello World”的Applet小程序。在划线处加入适当代码,使程序能够正常运行。 1: import java.awt.*; 2: import ; 3: public class HelloWorld extends Applet { 21 4: String text=“Hello World”; 5: pubic void paint (Graphics g) { 6: g. ; 7: } 8: } 5(在Java Applet程序运行时,当浏览器离开含有Applet的网页时被调用的方法是( )。 A stop ( ) B start ( ) C init ( ) D destroy ( ) 6(开发一个Applet小程序的第一步是需要引入相关的包和类,该语句为( )。 7(当用户退出浏览器时,Applet从系统中撤出停止自身执行,最后调用的方法是stop( )。 ( ) 8(下列的属性中属于可选属性的一项是( )。 A B C D 9(Java的用户程序分为两类,它们分别是 和 。 10(编写Applet过程的第一步是要定义一个 类型的类,且该类必须是 类的子类。 11(下列关于Applet程序的描述中,错误的是( )。 A Applet程序是一种独立的程序,它经过编译后可运行 B Applet程序的源文件的扩展名为 .java C Applet程序运行时要把它写到一个HTML文件中 D 使用Applet Viewer命令运行Applet程序的字节码文件被嵌入的HTML文件,便可得到运行结果 12(如果一个Java程序既是应用程序,又是小应用程序,那么它必定含有类___________的子类,同时含有成员方法___________。 13(Applet是一个面板容器,它的默认布局管理器是___________。 第9章:Java多线程 1(下列说法中错误的一项是( )。 A 线程一旦创建,则立即自动运行 B 线程创建后需要调用start()方法,将线程置于可运行状态 C 调用线程的start()方法后,线程也不一定能立即执行 D 线程处于可运行状态,意味着它可以被调度 2(Java的线程是通过 类来实现的,每个线程都是通过某个特定的线程类对象所对应 的 方法来完成其操作的,该方法成为线程体。 3(当编译运行下列代码时,会发生下列哪种情况( )。 public class Borley extends Thread { public static void main(String[ ] args) { Borley b=new Borley; b.start( ); } public void run { System.out.println(“Running”); } 22 } A 编译和运行都通过,但是没有输出结果 B 编译通过,运行时输出Running C 编译时错误,因为没有线程对象 D 编译时通过,但运行时错误 4(在一个类中下述哪一个方法可以作为新线程执行的起始点,是由系统调用的( )。 A public void start( ) B public void run( ) C public void init( ) D public void runnable( ) 5(创建线程的两种方法为( )和( )。 第10章:Java网络程序设计 1(Java中有关网络的类都包含在 包中。 2(Socket通信机制提供了两种通信方式,分别是 和 。 第11章:JDBC技术 1(下面不属于JDBC API的基本功能的选项是( )。 A 建立与一个数据源的连接 B 向数据源发送查询和更新语句 C 获取并处理得到的结果 D 对数据库进行备份和数据恢复处理 2(在Java中,JDBC是指( )。 A Java连接的数据库名称 B Java类编译程序 C Java程序与数据库连接的一种机制 D Java程序与浏览器交互的一种机制 、本地API部分Java驱动、网络协议完全Java,(JDBC驱动有四种类型: 驱动、 。 4(在JDBC中,指向数据库的URL中包含: 、 和数据库名称。 23 第3部分:SCJP认证试题 试题,: 1. Which of the following range of short is correct? 771615153131A. -2 ,2-1 B. 0 , 2-1 C. -2 ~,2-1 D. -2 ~,2-1 2. Which declarations of identifiers are legal? A. $persons B. TwoUsers C. *point D. this E. _endline 3. Which statement of assigning a long type variable to a hexadecimal value is correct? A. long number = 345L; B. long number = 0345; C. long number = 0345L; D. long number = 0x345L; 4. Which of the following fragments might cause errors? A. String s = "Gone with the wind"; String t = " good "; String k = s + t; B. String s = "Gone with the wind"; String t; t = s[3] + "one"; C. String s = "Gone with the wind"; String standard = s.toUpperCase(); D. String s = "home directory"; String t = s - "directory"; 5. Gien the flowing code: class Person { private int a; public int change(int m){ return m; } } public class Teacher extends Person { public int b; public static void main(String arg[]){ Person p = new Person(); Teacher t = new Teacher(); int i; // point x } } Which are syntactically valid statement at // point x? A. i = m; 24 B. i = b; C. i = p.a; D. i = p.change(30); E. i = t.b; 6. Which layout manager is used when the frame is resized the buttons's position in the Frame might be changed? A. BorderLayout B. FlowLayout C. CardLayout D. GridLayout 7. Given the following code fragment: 1:public void create() { 2: Vector myVect; 3: myVect = new Vector(); 4:} Which of the following statements are true? A. The declaration on line 2 does not allocate memory space for the variable myVect. B. The declaration on line 2 allocates memory space for a reference to a Vector object. C. The statement on line 2 creates an object of class Vector. D. The statement on line 3 creates an object of class Vector. E. The statement on line 3 allocates memory space for an object of class Vector. Which of the following answer is correct to express the value 8 in octal number? 8. A. 010 B. 0x10 C. 08 D. 0x8 9. Which are not Java keywords? A. TRUE B. sizeof C. const D. super E. void 10. Which of the following statements are true? A. The equals() method determines if reference values refer to the same object. B. The == operator determines if the contents and type of two separate objects match. C. The equals() method returns true only when the contents of two objects match. D. The class File overrides equals() to return true if the contents and type of two separate objects match. 11. Which statements about inheritance are true? A. In Java programming language only allows single inheritance. B. In Java programming language allows a class to implement only one interface. C. In Java programming language a class cannot extend a class and implement a interface together. D. In Java programming language single inheritance makes code more reliable. 12. Given the following code: 1:class Person { 2: public void printValue(int i, int j) {//... } 3: public void printValue(int i){//... } 4:} 25 5:public class Teacher extends Person { 6: public void printValue() {//... } 7: public void printValue(int i) {//...} 8: public static void main(String args[]){ 9: Person t = new Teacher(); 10: t.printValue(10); 11: } 12:} Which method will the statement on line 10 call? A. on line 2 B. on line 3 C. on line 6 D. on line 7 13. Which are not Java primitive types? A. short B. Boolean C. unit D. float 14. Use the operators "<<", ">>", which statements are true? A. 0000 0100 0000 0000 0000 0000 0000 0000<<5 gives 1000 0000 0000 0000 0000 0000 0000 0000 B. 0000 0100 0000 0000 0000 0000 0000 0000<<5 gives 1111 1100 0000 0000 0000 0000 0000 0000 C. 1100 0000 0000 0000 0000 0000 0000 0000>>5 gives 1111 1110 0000 0000 0000 0000 0000 0000 D. 1100 0000 0000 0000 0000 0000 0000 0000>>5 gives 0000 0110 0000 0000 0000 0000 0000 0000 15. Which of the following range of int is correct? 773215153131A. -2 , 2-1 B. 0 , 2-1 C. -2 , 2-1 D. -2 , 2-1 16. Which keyword should be used to enable interaction with the lock of an object? The flag allows exclusive access to that object. A. transient B. synchronized C. serialize D. static 17. Which is the return type of the method main()? A. int B. void C. boolean D. static 18. Given the following code: if (x>0) { System.out.println("first"); } else if (x>-3) { System.out.println("second"); } else { System.out.println("third"); } Which range of x value would print the string "second"? A. x > 0 B. x > -3 C. x <= -3 D. x <= 0 & x > -3 19. Given the following expression about TextField which use a proportional pitch font. TextField t = new TextField("they are good",40); Which statement is true? A. The displayed string can use multiple fonts. B. The maximum number of characters in a line will be 40. 26 C. The displayed width is exactly 40 characters. D. The user can edit the characters. 20. Which statements about the garbage collection are true? A. The program developer must create a thread to be responsible for free the memory. B. The garbage collection will check for and free memory no longer needed. C. The garbage collection allow the program developer to explicity and immediately free the memory. D. The garbage collection can free the memory used java object at expect time. 21. Which of the following assignment is not correct? A. float f = 11.1; B. double d = 5.3E12; C. double d = 3.14159; D. double d = 3.14D. 22. Given the uncompleted code of a class: class Person { String name, department; int age; public Person(String n){ name = n; } public Person(String n, int a){ name = n; age = a; } public Person(String n, String d, int a) { // doing the same as two arguments version of constructor // including assignment name=n,age=a department = d; } } Which expression can be added at the "doing the same as..." part of the cons tructor? A. Person(n,a); B. this(Person(n,a)); C. this(n,a); D. this(name,age); 23. Which of the following statements about variables and their scopes are true? A. Instance variables are member variables of a class. B. Instance variables are declared with the static keyword. C. Local variables defined inside a method are created when the method is executed. D. Local variables must be initialized before they are used. 24. Given the following code: public void test() { try { oneMethod(); System.out.println("condition 1"); } catch (ArrayIndexOutOfBoundsException e) { System.out.println("condition 2"); } catch(Exception e) { System.out.println("condition 3"); } finally { 27 System.out.println("finally"); } } Which will display if oneMethod run normally? A. condition 1 B. condition 2 C. condition 3 D. finally 25. Given the following code: public class Test { void printValue(int m){ do { System.out.println("The value is"+m); } while( --m > 10 ) } public static void main(String arg[]) { int i=10; Test t= new Test(); t.printValue(i); } } Which will be output? A. The value is 8 B. The value is 9 C. The value is 10 D. The value is 11 26. Which of the following statements about declaration are true? A. Declaration of primitive types such as boolean, byte and so on does not allocate memory space for the variable. B. Declaration of primitive types such as boolean, byte and so on allocates memory space for the variable. C. Declaration of nonprimitive types such as String, Vector and so on does not allocate memory space for the object. D. Declaration of nonprimitive types such as String, Vector ans so on allocates memory space for the object. 27. In the Java API documentation which sections are included in a class document? A. The description of the class and its purpose B. A list of methods in its super class C. A list of member variable D. The class hierarchy 28. Given the following code: 1:public void modify() { 28 2: int i, j, k; 3: i = 100; 4: while ( i > 0 ) { 5: j = i * 2; 6: System.out.println (" The value of j is " + j ); 7: k = k + 1; 8: i--; 9: } 10:} Which line might cause an error during compilation? A. line 4 B. line 6 C. line 7 D. line 8 29. Which of the following statements about variables and scope are true? A. Local variables defined inside a method are destroyed when the method is exited. B. Local variables are also called automatic variables. C. Variables defined outside a method are created when the object is constructed. D. A method parameter variable continues to exist for as long as the object is needed in which the method is defined. 30. A class design requires that a member variable cannot be accessible directly outside the class. Which modifier should be used to obtain the access control? A. public B. no modifier C. protected D. private 31. Given the following code fragment: 1:String str = null; 2:if ((str != null) && (str.length() > 10)) { 3: System.out.println("more than 10"); 4:} 5:else if ((str != null) & (str.length() < 5)) { 6: System.out.println("less than 5"); 7:} 8:else { System.out.println("end"); } Which line will cause error? A. line 1 B. line 2 C. line 5 D. line 8 32. Which statements about Java code security are true? A. The bytecode verifier loads all classes needed for the execution of a program. B. Executing code is performed by the runtime interpreter. C. At runtime the bytecodes are loaded, checked and run in an interpreter. D. The class loader adds security by separating the namespaces for the classes ofthe local file system from those imported form network sources. 33. Given the following code: 29 public class Person{ static int arr[] = new int[10]; public static void main(String a[]) { System.out.println(arr[1];) } } Which statement is correct? A. When compilation some error will occur. B. It is correct when compilation but will cause error when running. C. The output is zero. D. The output is null. 34. Given the following code: public class Person{ int arr[] = new int[10]; public static void main(String a[]) { System.out.println(arr[1];) } } ich statement is correct? Wh A. When compilation some error will occur. B. It is correct when compilation but will cause error when running. C. The output is zero. D. The output is null. 35. Given the following code: public class Parent { public int addValue( int a, int b) { int s; s = a+b; return s; } } class Child extends Parent { } Which methods can be added into class Child? A. int addValue( int a, int b ){// do something...} B. public void addValue (){// do something...} C. public int addValue( int a ){// do something...} D. public int addValue( int a, int b )throws MyException {//do something...} 30 36. A member variable defined in a class can be accessed only by the classes in the same package. Which modifier should be used to obtain the access control? A. private B. no modifier C. public D. protected 37. A public member vairable called MAX_LENGTH which is int type, the value of the variable remains constant value 100. Use a short statement to define the variable. A. public int MAX_LENGTH=100; B. final int MAX_LENGTH=100; C. final public int MAX_LENGTH=100; D. public final int MAX_LENGTH=100. 38. Which expressions are correct to declare an array of 10 String objects? A. char str[]; B. char str[][]; C. String str[]; D. String str[10]; 39. Which fragments are correct in Java source file? A. package testpackage; public class Test{//do something...} B. import java.io.*; package testpackage; public class Test{// do something...} C. import java.io.*; class Person{// do something...} public class Test{// do something...} D. import java.io.*; import java.awt.*; public class Test{// do something...} 40. Given the following code: String s = "hello"; String t = "hello"; char c[] = {'h','e','l','l','o'} ; Which return true? A. s.equals(t); B. t.equals(c); C. s==t; D. t.equals(new String("hello")); E. t==c. 41. Which of the following statements are legal? A. long l = 4990; B. int i = 4L; C. float f = 1.1; D. double d = 34.4; E. double t = 0.9F. 42. Given the following code: public class parent { int change() {} } class Child extends Parent { } 31 Which methods can be added into class Child? A. public int change(){} B. int chang(int i){} C. private int change(){} D. abstract int chang(){} 43. Given the following code: class Parent { String one, two; public Parent(String a, String b){ one = a; two = b; } public void print(){ System.out.println(one); } } public class Child extends Parent { public Child(String a, String b){ super(a,b); } public void print(){ System.out.println(one + " to " + two); } public static void main(String arg[]){ Parent p = new Parent("south", "north"); Parent t = new Child("east", "west"); p.print(); t.print(); } } Which of the following is correct? A. Cause error during compilation. B. south east C. south to north east to west D. south to north east E. south east to west 32 44. A Button is positioned in a Frame. Only height of the Button is affected by the Frame while the width is not. Which layout manager should be used? A. FlowLayout B. CardLayout C. North and South of BorderLayout D. East and West of BorderLayout E. GridLayout 45. Given the following code: 1:class Parent { 2: private String name; 3: public Parent(){} 4:} 5:public class Child extends Parent { 6: private String department; 7: public Child() {} 8: public String getValue(){ return name; } 9: public static void main(String arg[]) { 10: Parent p = new Parent(); 11: } 12:} Which line will cause error? A. line 3 B. line 6 C. line 7 D. line 8 E. line 10 46. The variable "result" is boolean. Which expressions are legal? A. result = true; B. if ( result ) { // do something... } C. if ( result!= 0 ) { // so something... } D. result = 1; 47. Class Teacher and Student are subclass of class Person. Person p; Teacher t; Student s; p, t and s are all non-null. if(t instanceof Person) { s = (Student)t; } What is the result of this sentence? A. It will construct a Student object. B. The expression is legal. C. It is illegal at compilation. D. It is legal at compilation but possible illegal at runtime. 48. Given the following class: 33 public class Sample{ long length; public Sample(long l){ length = l; } public static void main(String arg[]){ Sample s1, s2, s3; s1 = new Sample(21L); s2 = new Sample(21L); s3 = s2; long m = 21L; } } Which expression returns true? A. s1 == s2; B. s2 == s3; C. m == s1; D. s1.equals(m). 49. Given the following expression about List: List l = new List(6,true); Which statements are ture? A. The visible rows of the list is 6 unless otherwise constrained. B. The maximum number of characters in a line will be 6. C. The list allows users to make multiple selections D. The list can be selected only one item. 50. Given the following code: class Person { String name,department; public void printValue(){ System.out.println("name is "+name); System.out.println("department is "+department); } } public class Teacher extends Person { int salary; public void printValue(){ // doing the same as in the parent method printValue() // including print the value of name and department. System.out.println("salary is "+salary); } } Which expression can be added at the "doing the same as..." part of the method printValue()? A. printValue(); B. this.printValue(); C. person.printValue(); D. super.printValue(). 34 51. Which is not a method of the class InputStream? A. int read(byte[]) B. void flush() C. void close() D. int available() 52. Which class is not subclass of FilterInputStream? A. DataInputStream B. BufferedInputStream C. PushbackInputStream D. FileInputStream 53. Which classes can be used as the argument of the constructor of the class FileInputStream? A. InputStream B. File C. FileOutputStream D. String 54. Given the following code fragment: 1:switch(m) 2:{ case 0: System.out.println("case 0"); 3: case 1: System.out.println("case 1"); break; 4: case 2: 5: default: System.out.println("default"); 6:} Which value of m would cause "default" to be the output? A. 0 B. 1 C. 2 D. 3 55. Given the uncompleted method: 1: 2: { success = connect(); 3: if (success==-1) { 4: throw new TimedOutException(); 5: } 6:} TimedOutException is not a RuntimeException. Which can complete the method of declaration when added at line 1? A. public void method() B. public void method() throws Exception C. public void method() throws TimedOutException D. public void method() throw TimedOutException E. public throw TimedOutException void method() 56. Which of the following answer is correct to express the value 16 in hexadecimal number? A. 0xA B. 0x16 C. 0A D. 016 57. Which statements about thread are true? A. Once a thread is created, it can star running immediately. B. To use the start() method makes a thread runnable, but it does not necessarilystart immediately. C. When a thread stops running because of pre-emptive, it is placed at the frontend of the runnable queue. 35 D. A thread may cease to be ready for a variety of reasons. 58. The method resume() is responsible for resuming which thread's execution? A. The thread which is stopped by calling method stop() B. The thread which is stopped by calling method sleep() C. The thread which is stopped by calling method wait() D. The thread which is stopped by calling method suspend() 59. Given the following code: 1:public class Test { 2: int m, n; 3: public Test() {} 4: public Test(int a) { m=a; } 5: public static void main(String arg[]) { 6: Test t1,t2; 7: int j,k; 8: j=0; k=0; 9: t1=new Test(); 10: t2=new Test(j,k); 11: } 12:} Which line would cause one error during compilation? A. line 3 B. line 5 C. line 6 D. line 10 试题2: 1. Which are Java keywords? A. final B. transient C. NULL D. goto E. sizeof 2. Which are Java keywords? A. final B. transient C. NULL D. goto E. sizeof 3. Which are Java keywords? A. final B. transient C. NULL D. goto E. sizeof 4. To indicate that the SomeException is not handled in a method and it will be thrown out of the method to the calling method. Which is a correct declaration of the method? A. public void method() B. public SomeException method() C. public void method() throw SomeException D. public void method() throws SomeException 5. Given the following code: if (x>0) { System.out.println("first"); } 36 else if (x<10) { System.out.println("second"); } else { System.out.println("third"); } Which range of x value would print the string "second"? A. x <= 0 B. x < 10 & x > 0 C. x > 0 D. x >= 10 6. Which method can you use to make a thread runnable? A. runnable() B. run() C. start() D. init() 7. Which method can you use to make a thread runnable? A. runnable() B. run() C. start() D. init() 8. Given the code fragment: switch(n) { case 0: System.out.println("first"); case 1: case 2: System.out.println("second"); break; default: System.out.println("end"); } Which value of n would cause the string "second" to be output? A. 0 B. 1 C. 2 D. 3 9. Which statement about Java Virtual Machine is not true? A. The Java Virtual Machine provides the hardware platform specifications B. The Java software is platform independent because the compilation is done for Java Virtual Machine. C. The majority of type checking is done when the code is running. D. The Java Virtual Machine provides the definitions for the class file form at. 10. A Button is positioned in a Frame. Only width of the Button is affected by the Frame while the height is not. Which layout manager should be used? A. FlowLayout B. CardLayout C. North and South of BorderLayout D. East and West of BorderLayout E. GridLayout 11. Which components cannot be added to container? A. Button B. MenuItem C. Choice D. HelpMenu 12. Given the following: import java.awt.event.*; import java.awt.*; class Test implements ...{ // do something } 37 Which listeners must be inserted in the place ... to enable the programme to pick up ActionEvent and WindowEvent? A. ActionListener B. WindowListener C. ActionListener,ContainerListener D. ActionListener,WindowListener 13. Which menu component can be added to any component? A. MenuBar B. HelpMenu C. CheckboxMenuItem D. PopupMenu E. Menu 14. Given the following expression about TextArea which use a proportional pitch font. TextArea t = new TextArea ("abcdefg", 4, 7); Which statements are true? A. It can set to read-only by using the method setEditable(). B. The displayed string can use multiple fonts. C. The maximum number of characters in a line will be 7. D. The displayed height is 4 lines otherwise constrain. 15. In order to implement the MouseMotionListener interface, which of the following methods are required? A. mouseDragged B. mousePressed C. mouseEntered D. mouseClicked E. mouseMoved 16. Which of the following are standalone components? A. Panel B. Window C. Frame D. ScrollPane E. FileDialog 17. What is the main task that javac command in JDK does? A. Executes code B. Verifies code C. Loads code D. Compiles code 18. Which of the following component requires a call to requestFocus() method to receive user input? A. Choice B. Canvas C. Button D. MenuItem E. Panel 19. Which security requirements can be met after the code verified by ByteCode Verifier? A. The code does not violate system integrity. B. The code causes no operand stack overflows or underflows. C. No illegal data conversions have occurred. D. The parameter types for all operational code are correct. E. The code adheres to the JVM specification. 20. Which of the following are permissible styles of comment in Java program? A. /** */ B. // C. rem D. /* */ E. " " 21. Which of the following does the JVM specification provide definitions? A. Class file format B. Instruction set C. Stack D. Code security 38 22. Which is the result of user action on an AWT component? A. Event handler B. Event C. Event listener D. The method in event listener 23. Which of the following identifiers are legal? A. first-price B. _username C. This D. Method1.1 E. Str2 24. Given the following definition of a class which expression added at //pointx is correct? public class Test { int x, y; public static void main(String args[]) { Test s, t; s = new Test(); // point x } } A. x = 10; B. s.y = 2; C. t.x = 3; D. t.y = 10. 25. Given the following code: public class Test { public static void main(String arg[]) { int j = 0; while ( j++ < 3 ) { System.out.println("j is "+j); } System.out.println("finished"); } } Which will be output? A. j is 0 B. j is 1 C. j is 2 D. j is 3 E. j is 4 F. finished 26. Which of the following statements are correct to create an empty String array of 6 elements? A. String s[6]; B. String [6]s; C. String s[]={ "","","","","","" }; D. String s[]=new String[6]; for ( int m=0; m<6; m++) { s[m]=""; } E. String s[]=new String[6]; for ( int m=0; m<6; m++) { s[m]=null; } 27. Given the following code: public class MyClass { public static void main(String arg[]){ int arr[]=new int[3]; System.out.println("it is "+arr[1]); 39 } } When compile and run this code what will be happen? A. There is a compilation error "possible reference before assignment" B. There is a compilation error "illegal array declaration syntax" C. There is an exception "NullPointerException" D. It runs correctly and "it is 0" is output. 28. Given the following definition of a class: public class Person { String name; int age; public Person(String n, int a) { name = n; age = a; } public static void main(String arg[]){ // point x } } Which can be added at point x? A. Person p[]=new Person[3]; p[1]= new Person("user1"; 24); B. Person p[]; p=new Person[3]; p[2]=new Person("user2"; 56); C. Person p[]={ new Person("user1",34), new Person("user2",34) }; D. Person p[]= new Person{ ("user1",34),("user2",34) }. 29. Given the following code: public class Test{ String s; int m; public Test(String t, int n) { s=t; m=n; } public static void main(String arg[]){ Test t[]={ new Test("abc",3), new Test("ddf",23) }; // point x } } 40 Which of the following expressions are legal to be added at point x? A. System.out.println("the value is "+ t[3].s); B. System.out.println("the value is "+ t[2].m); C. System.out.println("the value is "+ t[1].s); D. System.out.println("the value is "+ t[1].m); 30. Given the following variables which expressions are correct? boolean result; char c, t; float f; A. c = 'a'; B. f = 10.0; C. t = c; D. result = True; E. result = 1; 31. Which class provides a template for implementing the appropriate listener interface and leaves the implemented method empty? A. Event B. Event listener C. Event adapter D. Event handler 32. Which of the following is correct declaration of class in the file Example.java? A. public class example{ private char c; public example(char ch) { c = ch; } } B. public class Example{ public char c; public Example(char ch) { c = ch; } } C. public class Example extends Base1,Base2 { private char c; public Example(char ch) { c = ch; } } D. private class Example extends Base { private char c; public Example(char ch) { c = ch; } } E. public class Example1 extends Object { 41 private char c; public Example(char ch) { c = ch; } } 33. Which of the following overloading methods are legal? public void method(int m, String str){...} A. public void method(String str,int m){...} B. public int method(int m, String str){...} C. public int method(int m, String str, int n){...} D. public void method(int m){...} 34. Given the content of the file Test.java. There is an error during compilation. 1:public class Test{ 2: void createObject(){ 3: Child c = new Child("doctors"); 4: Parent p = new Parent("person"); 5: } 6:} 7:class Child extends Parent{ 8: String s; 9: public Child(String t){ s = t; } 10:} 11:class Parent { 12: public Parent(){} 13:} Which line might cause the error? A. 3 B. 4 C. 7 D. 9 E. 11 35. Which of the following exception is not Java pre-defined Exception? A. ArithmeticExceptoin B. NullPointerException C. SecurityExceptoin D. ArrayOutOfLengthException E. NegativeArraySizeException 36. Which of the following declarations of arrays are legal? A. char c[][]=new char[2][3]; B. char c[][]=new char[6][]; C. char [][]c=new char[3][3]; D. char [][]c=new char[][4]; 37. Which statement defines a block of code that always executes, regardless of whether or not an exception was thrown? 42 A. catch B. finally C. final D. throw E. throws 38. Given the following code: void test(){ int m = 1; switch (m) { case 0: m += 1; break; case 1: m += 2; case 2: m -= 3; break; default: m *= 4; break; } System.out.println("the value of m is "+m); } Which will be output when the method test() is called? A. 0 B. 1 C. 2 D. 3 E. 4 39. Which statement identifies that an exception occurs? A. try B. catch C. throw D. finally 40. Which method will the repaint() cause the AWT thread to call? A. start() B. paint() C. init() D. update() E. run() 41. Which methods can be called to stop the current thread's execution temporary ? A. stop() B. sleep() C. wait() D. suspend() 42. Which class includes the drawImage(), drawstring(), setColor() methods? A. java.awt.Applet B. java.awt.Image C. java.awt.Graphics D. java.util.Date 43. Which method is called at the time the applet is first loaded into a browser and can be used to initialize data values? A. start() B. run() C. paint() D. update() E. init() 44. Given the following code: public class MyClass { public static void main(String arg[]) { int m = 0; int n = 0; label1: for (n; n<2; n++) { if (m>=1) { continue label1; } System.out.println("the values are " + m + " " + n); } } } Which will be output? A. the values are 0 0 B. the values are 1 0 43 C. the values are 2 0 D. the values are 0 1 E. the values are 1 1 F. none 45. Which method is called when the applet becomes invisible? A. stop() B. update() C. repaint() D. paint() 46. Which of the following layout manager is illegal? A. FlowLayout B. BorderLayout C. CardBagLayout D. GridLayout 47. Which layout manager does not constrain the size of the component it manages, but instead allows them to have their preferred size? A. FlowLayout B. BorderLayout C. CardLayout D. GridLayout lasses are subclasses of the class java.awt.Component? 48. Which c A. Canvas B. Choice C. MenuBar D. TexArea E. Image 49. Which class is a legal argument of the constructor in the class FilterOutput Stream? A. File B. InputStream C. OutputStream D. FileOutputStream 50. Which methods provide information of file name? A. isFile() B. getName() C. getAbsolutePath() D. exists() 51. Given the following code: public class TestThread implements Runnable { public void run() { // do something } } Which of the following statements construct a thread correctly? A. Thread t = new Thread(); B. Runnable r = new TestThread(); Thread t = new Thread(r); C. Runnable r = new TestThread(); Threat t = new Thread(); D. TestThread r = new TestThread(); Thread t = new Thread(r); 52. Which layout manager has both of the two characters? 1:the relative position of components does not change as the area is resi zed. 2:the order in which components are added determines the position that they occupy. A. FlowLayout B. BorderLayout C. GridLayout D. CardLayout 53. Which methods are used to communicate of threads? A. wait() and notify() B. suspend() and resume() C. start() and stop() 44 D. run() E. join() 54. Which of the following classes is provided in Java to support TCP/IP connection? A. InetAddress B. Packet C. Socket D. ServerSocket 55. Which constructor defines sending data used in the User Datagram Protocol? A. DatagramSocket(int port) B. DatagramSocket(int port, InetAddress iaddr) C. DatagramPacket(byte[] buf, int length) D. DatagramPacket(byte[] but, int length, InetAddress iaddr, int iport) 56. Given the following uncompleted method: 1:// declaration of a method 2:{ int result; 3: result = connect ( ); 4: if ( result == -1 ) { 5: 6: } 7:} Which clause can be added at line 5 where a user-defined MyException will be thrown? A. throw MyException; B. throws MyException; C. throw new MyException(); D. throws new MyException(); 57. Given the following method: public void test () { try { oneMethod (); System.out.println ( "condition 1"); } catch ( ArithmeticException e ) { System.out.println ( "condition 2" ); } catch ( Exception e ) { System.out.println ( "condition 3"); } finally { System.out.println ("condition 4" ); } } Which will display if oneMethod throw NullPointerException? A. condition 1 B. condition 2 C. condition 3 D. condition 4 58. Given the following code of an entire file: 1:public class Test { 2: int m, n; 45 3: public void add() { m = m+1; n = n+1; } 4: public void add( int a, int b ) { m = m+a; n = n+b; } 5: public static void main ( String arg[] ) 6: { Test t1, t2; 7: int j, k; 8: j = 5; k=6; 9: t1 = new Test ( ); 10: t2 = new Test ( ); 11: t1.add( j ); 12: t2.add( j, k ); 13: } 14:} Which line would cause one error during compilation? A. line 2 B. line 4 C. line 9 D. line 11 59. Given the following code fragment in a java source file: 1: 2:public class Test { 3: // do some thing 4:} Which statements are correct to add at line 1 ? A. public class Result { int score; } B. import java.applet.*; C. package testpackage; D. import java.io.*; 60. Which of the following layout manager is the default layout manager of Windows and Dialogs? A. GridLayout B. BorderLayout C. FlowLayout D. CardLayout E. GridBagLayout 46
/
本文档为【第3部分SCJP认证试题-沈阳师范大学】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索