试题库-1.docx_第1页
试题库-1.docx_第2页
试题库-1.docx_第3页
试题库-1.docx_第4页
试题库-1.docx_第5页
已阅读5页,还剩5页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

一、选择题1. 当我们定义变量时,下列哪个是错误的?( C )A、_sysB 、$changeC 、1nameD、thisOne2. 当我们定义类名,下列哪个是错误的?(B )A、EmployeeB 、3GC 、helloworldD、Hello$World3. 在Java中,整型int存储的字节长度为( C )A、1 B、2 C、4 D、84. 查看下列代码,说法正确的是( B )。byte b = 10;short s = 200;short c = b + s;A、程序执行正确。 B、程序编译错误。5. 当我们定义不同类型的变量时,哪个是错误的?( A )A、byte b = 128 B、char a = a C、double d = 1.3d D、float f = 3.1415f6. MyClass类的默认构造器是( B )A、new MyClass() B、MyClass() C、MyClass D、public class MyClass7. 构造函数何时被调用?( A )A、创建对象时 B、类定义时C、使用对象的方法时 D、使用对象的属性时8. 下列定义数组正确的是( ABD )选三项A、String s1 = new String4; B、String s2 = a,b; C、String s4 = String4; D、String s3 = new String4;E、char s5 = null;9. 下面定义一个String值是正确的是( BCE )选三项A、String a = Im a String; B、String b = Im a String; C、String c = new String(); D、String d = Im as String;E、String e = new String(Im a String);10. 以下关于构造函数的描述错误的是( A )。A、构造函数的返回类型只能是void型。B、构造函数是类的一种特殊函数,它的方法名必须与类名相同。C、构造函数的主要作用是完成对类的对象的初始化工作。D、一般在创建新对象时,系统会自动调用构造函数。11. 设有下面两个赋值语句: a = Integer.parseInt(“12”); b = Integer.valueOf(“12”).intValue(); 下述说法正确的是( D )。 A、a是整数类型变量,b是整数类对象。 B、a是整数类对象,b是整数类型变量。 C、a和b都是整数类对象并且值相等。 D、a和b都是整数类型变量并且值相等。12. 在Java中,一个类可同时定义许多同名的方法,这些方法的形式参数个数、类型或顺序各不相 同,传回的值也可以不相同。这种面向对象程序的特性称为( C )。A、隐藏 B、覆盖 C、重载 D、Java不支持此特性13. 下列X,Y,和Z都是接口。下列正确的接口声明是什么( AC )。选二项A、public interface A extends Xvoid aMethod();B、interface B implements Y void aMethod();C、interface C extends X,Y,Z void aMethod();D、interface C extends X protected void aMethod();14. 以下关于继承的叙述正确的是( A )。A、在Java中类只允许单一继承B、在Java中一个类只能实现一个接口C、在Java中一个类不能同时继承一个类和实现一个接口D、在Java中接口只允许单一继承15. 给出下面代码,关于该程序以下哪个说法是正确的?( A )public class Person int arr = new int5; public static void main(String a) System.out.println(arr0); A、编译时将产生错误 B、编译时正确,运行时出错 C、输出零 D、输出空16. 下列抽象类定义正确的是哪个?( C )A、class MyClass abstract void hello(); B、abstract Myclass abstract void hello();C、abstract class MyClass abstract void hello(); D、abstract class MyClass abstract void hello(System.out.println(hello!););17. 查看下面的程序LoginApp.javaclass Userprivate String name;private String pwd;private User()public class LoginApppublic static void main(String args)User user = new User();以下说法正确的是( A )。A、程序不能正确编译。 B、程序能正确编译,user是已实例化的对象。C、程序能正确编译,user不能被实例化对象。 D、程序能正确编译。18. 查看下列代码public class MyClassprivate String loginName;public static void main(String args) System.out.println(this.loginName);以下说法正确的是( A )。A、程序不能正确编译。 B、程序能正确编译,打印loginName的内容。C、程序能正确编译,不能打印loginName,因为loginName没有给初始值。D、程序能正确编译。19. 下列哪些是正确的( ABC )。选三项A、private final String loginName = ;B、final int i = 0;C、static final String s = ;D、const final int m = 0;E、private final String name;20. 下列说法正确的有( C )A、class中的constructor不可省略。B、 constructor必须与class同名,但方法不能与class同名。C、 constructor在一个对象被new时执行。D、一个class只能定义一个constructor。21. 下面哪个流类属于面向字符的输入流( D )。A、BufferedWriter B、FileInputStream C、ObjectInputStream D 、InputStreamReader22. Java接口的修饰符可以为( CD )。选二项A、private B、 protected C、 final D、 abstract23. 当我们新建一个流对象,下面哪个选项的代码是错误的?( B )A、new BufferedWriter(new FileWriter(a.txt);B、new BufferedReader(new FileInputStream(a.dat);C、new GZIPOutputStream(new FileOutputStream(a.zip);D、new ObjectInputStream(new FileInputStream(a.dat);24. 查看下列代码:public class foo public static void main (String args) String s1; System.out.println(s1= + s1); 下列哪个说法是正确的( C )。A、 代码得到编译,并输出“s=”。B、 代码得到编译,并输出“s=null”。C、 由于String s没有初始化,代码不能编译通过。D、 代码得到编译,但捕获到 NullPointException异常。25. 下列哪种异常是检查型异常,需要在编写程序时声明 ( C )A、NullPointerException B、ClassCastException C、FileNotFoundException D 、IndexOutOfBoundsException26. 选项中哪一行代码可以替换题目中/add code here而不产生编译错误?( A )查看下列代码:public abstract class MyClass public int constInt = 5; /add code here public void method() A、public abstract void method(int a);B、 constInt = constInt + 5;C、 public int method();D、 public abstract void anotherMethod() 27. importCustomerInfo()方法如下,try中可以捕获三种类型的异常,如果在该方法运行中产生了一个IOException,将会输出什么结果( )。查看下列代码:public void importCustomerInfo() try / do something that may cause an Exception catch (java.io.FileNotFoundException ex) System.out.print(FileNotFoundException!); catch (java.io.IOException ex) System.out.print(IOException!); catch (java.lang.Exception ex) System.out.print(Exception!); 哪个是正确的输出( A )。A、IOException!B、IOException!Exception!C、FileNotFoundException!IOException!D、FileNotFoundException!IOException!Exception!28. 关于异常处理机制的叙述哪些正确( BC )。A、catch部分捕捉到异常情况时,才会执行finally部分。B、当try区段的程序发生异常时,才会执行catch区段的程序。C、不论程序是否发生错误及捕捉到异常情况,都会执行finally部分。D、以上都是。29. 在Java Applet程序用户自定义的Applet子类中,一般需要重载父类的( D )方法来完成一些画图操作。 A、start( ) B、stop( ) C、init( ) D、paint( )30. 下面哪些是Thread类的方法( ABD )。选三项A 、start() B、 run() C、 exit() D、 getPriority()二、代码阅读题1. 阅读下列代码,请写出它的运行输出结果:程序:public class TestOperpublic static void main(String args) int i = 0;System.out.println(i=0;(i+)=+(i+);System.out.println(i= +i);i = 0;System.out.println(i=0;(+i)=+(+i); 结果:i=0;(i+)=0i=1i=0;(+i)=12. 阅读下列程序,请写出运行结果并说明原因。String str1 = hello;String str2 = he + new String(llo);System.err.println(str1 = str2);结果:false,因为str2中的llo是新申请的内存块,而=判断的是对象的地址而非值,所以不一样。3. 阅读下列程序,请写出运行结果。当i输入值为2时。public static int getValue(int i) int result = 0; switch (i) case 1: result = result + i; case 2: result = result + i * 2; case 3: result = result + i * 3; return result; 结果:104. 阅读下列程序,请写出运行结果。class HelloA public HelloA() System.out.println(HelloA); System.out.println(Im A class); static System.out.println(static A); public class HelloB extends HelloA public HelloB() System.out.println(HelloB); System.out.println(Im B class); static System.out.println(static B); public static void main(String args) new HelloB(); 结果:static Astatic BIm A classHelloAIm B classHelloB5. 阅读下列程序,请写出运行结果。class Fatherpublic void show()System.out.println(father show.);class son extends Fatherpublic void show()System.out.println(sun show.);public class Sample1 public static void main(String args) Father f1 = new son();Father f2 = new Father();f1.show();f2.show();结果:sun show.father show.6. 阅读下列程序,请写出运行结果。public class Sample2 String str = new String(ok); char ch = a, b, c ;public static void main(String args) Sample2 s2 = new Sample2();s2.change(s2.str, s2.ch); System.out.print(s2.str + and ); System.out.print(s2.ch); public void change(String str, char ch) str = test ok; ch0 = g; 结果:ok and gbc7. 阅读下列程序,请写出运行结果。public class StaticTest static int x=1;int y;StaticTest()y+; public static void main(String args) StaticTest st=new StaticTest(); System.out.println(x= + x); System.out.println(st.y= + st.y);st=new StaticTest();System.out.println(st.y= + st.y);static x+;结果:x=2st.y=1st.y=18. 阅读下列程序,请写出结果:class MealMeal()System.out.println(Meal();class BreadBread()System.out.println(Bread();class Lunch extends MealLunch()System.out.println(Lunch();class PortableLunch extends LunchPortableLunch()System.out.println(PortableLunch();public class Sandwich extends PortableLunchprivate Bread b = new Bread();public Sandwich()System.out.println(Sandwich();public static void main(String args) new Sandwich();结果:Meal()Lunch()PortableLunch()Bread()Sandwich()9. 阅读下列程序,请写出结果:abstract class Basepublic Base(int i)System.out.println(Base(),i=+i); public abstract void f();public class AnonymousConstructor public static Base getBase(int i)return new Base(i)public void f() System.out.println(f();public static void main(String args) Base base = getBase(40);base.f();结果:Base(),i=40f()10. 阅读下列程序,请写出结果:class ThreeException extends Exce

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论