1、Java模拟试题共三大题一、单项选择题(1*60,共计60分)1.对象之间的基本关系是:A包含 继承B包含 继承 关联C包含 关联D没有2.下列说法正确的是:A“清华大学”是一个类B“大学”是一个类C“大学“和”清华大学“之间是继承的关系D“大学“和”清华大学“之间没有关系3.面向对象程序设计方法的优点:A可重用性、可扩展性、可操作性B可重用性、可维护性、可操作性C可管理性、可扩展性、可操作性D可重用性、可扩展性、可管理性 4.下面那一项不会出现编程错误:A.忘记多行注释符的一个定界符B.一个标识符的大小写字母使用不当C.括号不成对出现D.在一个显示图形用户界面的应用程序中调用System .
2、exit5.下面这些标识符那些是错误的:A.MyGameB._isHersC.2JavaProgramD.+$abc6.所有的程序均可以用几种类型控制结构编写:A顺序结构、选择结构、循环结构B顺序结构、循环结构C顺序结构、选择结构D选择结构、循环结构7.当条件为真和条件为假时,控制结构可以执行不同的动作。AswitchBwhileCforDif/else8.当事先不知道语句重复执行的次数时,可以用一个值来终止循环。A布尔 B正C标记D负9.请看下面的程序代码:if(x0) System .out .println(“first”);else if(x10) System .out .print
3、ln(“second”);else System .out .println(“third”) 当程序输出“second”时,X的范围为:Ax = 0Bx 0Cx 0Dx = 1010.线性表和表可以存储在中。A数组B堆栈C文件 D字符串11.二维数组使用几个下标。A1B2 C3D412.请看下面的程序段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
4、 n,String d,int a) /doing the same as two arguments version of constructer/including assignment name=n,age=a下面那一选项可以添加到“/doing the same”处:APerson(n,a)Bthis(Person(n,a)Cthis(n,a)Dthis(name.age)13.是一个特殊的方法,用于对类的实例变量进行初始化。A终止函数B构造函数C重载函数D初始化函数14.关键字表明一个对象或变量在初始化后不能修改。AextendsBfinalCthisDfinalizer15.声明为
5、static的方法不能访问类成员。A超类B子类C非staticD用户自定义类16.如果超类不允许其通过继承的方式产生的子类访问它的某些成员,那么它必须以什么方式声明该成员。A. publicB. privateC. protectedD. static17.如果在你的类的层次结构的类中定义了finalize方法,它总是被定义为什么类型以便子类能访问该方法。A. publicB. privateC. protectedD. static18.声明为final的变量不能在子类中覆盖,声明为( )和( )的方法是隐式的final。A. public privateB. private protect
6、edC. protected staticD. static private19.使用多态性减少了逻辑的使用。AforBwhileCifDswitch20.在运行时才确定调用那一个方法,这叫做绑定。A静态B动态C自动D快速21.请看下面的代码String s1=new String(“hello”);String s2=new String(“there”);String s3=new String( );下面选项中语句正确的是:As3=s1+s2;Bs3=s1-s2;Cs3=s1&s2;Ds3=s1&s2;22.请看下面的代码public class StrEqpublic static v
7、oid main(String argv )StrEq s = new StrEq( );private StrEq( )String s = “Marcus”;String s2 = new String(“Marcus”);If(s = s2)System .out .println(“we have a match”);elseSystem .out .pritln(“Not equal”);A由于使用“private StrEq”编译时会出现错误B输出“we have a match”C输出“Not equal”23.跳过try块的异常处理程序,程序在最后一个块后开始执行。Afinal
8、lyBcatchCfinally或catch D任意24.对象一般是Java系统中的严重问题。AErrorBExceptionCThrowableD任何25.下面选项中,Java对类Welcome进行定义正确的是:Apublic class 1WelcomeBpublic class We lcomeCpublic class welcomeDpublic class Welcome26.有如下的程序:public class Welcome3 public static void main( String args )System.out.println( WelcomentonJavanP
9、rogramming! );则它的输出结果是:AWelcome to Java Programming!BWelcomentonJavanProgramming!CWelcome to Java Programming!DWelcome to JavaProgramming! 27.采用类名后跟一点(.)和方法名的形式调用什么方法?A静态B动态C静态和动态D任何28.请选择下面那一条语句是正确的:A if ( c 4 )JoptionPane.showMessageDialog( null,“c is less than 4 ”);B if ( c 4 );JoptionPane.showMe
10、ssageDialog( null,“c is less than 4 ”);C if ( c 4 )JoptionPane.showMessageDialog( null,“c is less than 4 ”)D if ( c = 10);public static void main(String arg)int I=10;Test t= new Test();t.printValue(i);A8B9C10D1132.下面程序的那一行可能引发错误:1:public void modify()2: int I,j,k;3: i=100;4: while( i 0)5: j=i*2;6: S
11、ystem .out .println(“The value of j is”+j);7: k = k + 1;8: i- -;9: 10: A4B6C7D833.下面程序的那一行可能引发错误: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 .pri
12、ntln(“end”); A1B2C5D834.如果result是布尔变量,下面哪个选项是正确的:Aresult = true;Bif(result)/do somethingCif(result!=0)/do somethingDresult = 1;35.请看下面的程序段:public class Personstatic int arr = new int10;public static void main(String a) System .out .println(arr1);下面说法正确的是:A当编译时会发生错误B编译不会发生错误但执行是会发生错误C输出结果为0D不会输出结果36.
13、请看下面的程序段:public class Personint arr = new int10;public static void main(String a) System .out .println(arr1);下面说法正确的是:A当编译时会发生错误B编译不会发生错误但执行是会发生错误C输出结果为0D不会输出结果37.下面哪个选项正确的声明一个字符型数组:Achar strBchar strCString strDString str1038.请看下面的程序段:public class MyClass public static void main(String arg ) int ar
14、r = new int3;System .out .println(“it is “+ arr1);当编译和执行这段代码时会出现:A有一个编译错误为“possible reference before assignment”B有一个编译错误为“illegal array declaration syntax”C有异常出现为“NullPointerException”D正确执行并且输出039.请看下面的程序段class Testprivate int m;public static void fun()/some code方法fun()如何来访问变量m:A将private int m改成prot
15、ected int mB将private int m改成public int mC将private int m改成static int m D将private int m改成int m40.在Java中,方法main()将返回一个值。AStringBintCcharDvoid41.请看下面的程序段int i = 1;int j;j = i+在程序段运行后,i和j的值为:A1,1B1,2C2,1D2,242.请看下面的程序段public class Test long a = new long10;public static void main(String arg ) System .out
16、.println(a6);那一个选项是正确的:A不输出任何内容B输出0C当编译时有错误出现D当运行时有错误出现43.继承性使成为可能,它不仅节省开发时间,而且也鼓励人们使用已经验证无误和调试过的高质量软件。A节省时间B软件复用C软件管理D延长软件生命周期44.如果Alpha类继承Beta类,Alpha类被称为类。 A超类B子类C系统D用户自定义45.在上题中,Beta类被称为类。A超类B子类C系统D用户自定义46.一个类的对象可以当作相应的类对象看待。A子 系统B用户 系统C子 超D超 用户47.请看下面的代码1.class Example 2. String str;3. public Ex
17、ample( )4. str = “example”;5. 6. public Example(String s)7. str = s;8. 9.10.class Demo extends Example 11.12.public class Test13. public void f()14. Example ex = new Example(“good”);15. Demo d = new Demo(“Good”);16. 17.那一行将导致发生错误:A3B6C10D14E1548.请看下面的代码public class ExampleString str = new String(“he
18、llo”);Char ch =d,b,c;public static void main(String args )Example ex=new Example( );ex.change(ex.str,ex.ch);System .out .println(ex.str +“and”+ex.ch);public void change(String str,char ch )str=”world”;ch0=a;该程序的输出结果是:Ahello dbcBhello abcCworld dbcDworld abc49.下面选项正确的是:AString temp = new String“j”a”z
19、”;BString temp = “j”a”z”;CString temp= “j”,”a”,”z”;DString temp = “j”,”a”,”z”;50.块可以防止资源泄露。AfinallyBcatchCfinally或catch D任意51.下面选项中的异常处理不是Java中预定以好的:AArithmeticExceptionBNullPointerExceptionCSecurityExceptionDArrayOutOfLengthExceptionE. NegativeArraySizeException52.用什么来声明一个出来处理:AtryBcatchCthrowDfina
20、lly53、下列哪一种布局管理器将容器分为“东、西、南、北、中”五个部分?( )A. FlowLayout B. BorderLayout C. GridLayout D. CardLayout E. GridBagLayout54、关于Applet的生命周期正确的说法有( )。A. init()方法在start()方法之后执行 B. init()方法可执行多次C. stop()方法在Applet退出时被调用,只调用一次D. stop()方法在Applet不可见时被调用,可以被调用多次55、实现下列哪个接口可以对 TextField 对象的事件进行监听和处理? ( ) A. MouseMoti
21、onListener B. FocusListener C. ActionListener D. WindowListener 56、监听事件和处理事件( )。 A. 都由 Listener 完成 B. 由 Listener 和窗口分别完成 C. 由 Listener 和组件分别完成 D. 都由相应事件 Listener 处登记过的组件完成57、下面语句正确的是:( )A. RandomAccessFile raf = new RandomAccesssFile(“myfile.txt”,”rw”) B. RandomAccessFile raf = new RandomAccesssFile
22、(new DataInputStream()C. RandomAccessFile raf= new RandomAccesssFile(“myfile.txt”)D. RandomAccessFile raf = new RandomAccesssFile(new File(“myfile.txt”)58、( )类是java.lang包中的一个专门用来创建线程和对线程进行操作的类。A. Runnable B. Thread C. Synchronized59、Java Application程序执行的入口是( )方法。Ainit() B. main() C.stop() D.start()6
23、0、Java Applet程序执行的入口是( )方法。Ainit() B. main() C.stop() D.start()二、多重选择题(2*20,共计40分)1.请看下面的程序代码:switch(n) case 0: System .out .println(“first”);case 1: case 2: System .out .println(“second”); break;default: System .out .println(“end”);当n为何值时,程序段将输出字符串second:A0B1C2D32.数组元素之所以相关,是因为它们具有相同的。A名字B类型C下标D地址3
24、.请看下面的程序段public class PersonString name;int age;public Person(String n,int a) name=n;age=a;public static void main(String arg )/point x下面选项可以添加到/point x处:APerson p =new Person3;P1=new Person(“user1”;24);BPerson p ;P=new Person3;P=new Person(“user2”;56);CPerson p = new Person(“user1,34),(“user2”,34)D
25、Person p =new Person(“user1,34),(“user2”,34)4.请看下面的程序段public class TestString 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 下面选项可以添加到/point x处:ASystem .out .println(“the value is”+t3.s);BSystem .out .println(“t
26、he value is”+t2.m);CSystem .out .println(“the value is”+t1.s);DSystem .out .println(“the value is”+t1.m);5.下面那一个不是Java的关键字:A TRUEB sizeofC constD superE. void 6.下面语句书写错误的是:AString s = “Gone with the wind”;String t = “good”;String k = s + t;BString s = “Gone with the wind”;String t;t = s3 + “one”;CSt
27、ring s = “Gone with the wind”;String standard = s.toUpperCase( );DString s = “home directory”;String t = s - “directory”;7.请看下面的代码String s = “hello”;String t = “hello”;String c = h,e,l,l,o; 下面哪一选项的语句返回值为真:As .equals(t);Bt .equals(c);Cs=t;Dt .equals(new String(“hello”);E. t=c;8.请看下面的代码String s = “sto
28、ry”;下面选项语句书写正确的是:As += “books”;Bchar c = s1;Cint len = s .length;DString t = s.toLowerCase( );9.使用catch(Exception e)的好处是。A只会捕获个别类型的异常B捕获try块中产生的所有类型的异常C不会漏掉所产生的异常D执行一些程序10.请看下面的代码public void test( ) try oneMethod( );System .out .println(“condition 1”); catch (ArrayIndexOutOfBoundsException e) System
29、 .out .println(“condition 2”);catch (Exception e) System .out .println(“condition 3”); finally System .out .println(“condition 4”);如果oneMethod抛出NullPointerException,则程序输出结果为:Acondition 1Bcondition 2Ccondition 3Dcondition 411. 请看下面的代码public void fun( ) int i;try i=System .in .read( );System .out .pri
30、ntln(“location 1”); catch (IOException e) System .out .println(“location 2”); finally System .out .println(“location 3”);System .out .println(“location 4”);如果IOException块执行,程序的输出结果为:Alocation 1Blocation 2Clocation 3Dlocation 412.下面那一个选项正确创建一个空的含有6个元素的字符数组:AString s6;BString 6s;CString s =“”,”,”,”,”,
31、”;DString s =new String6;For(int m=0;m6;m+) sm=”;E. String s =new String6;For(int m=0;m6;m+) sm=null; 13.关于变量和它们范围的说法,正确的是:A实例变量是类的成员变量B实例变量要用关键字static来声明C在一个方法执行时,定义在该方法的局部变量才被创建D局部变量必须在它们使用前初始化14.四种成员访问形式是。ApublicBprivateCprotectedD包访问15.下面选项正确创建一个字符型数组(含有4个元素)的是:AString a = new String4;for(int i=
32、0;i4;ai+=”);BString a =“”,”,”,”;CString a4;DString 4a;E. String a = new String4;For(int i=0;i t2 ? t1 : t2+ t1;t5 = t4 t3 ? t4 : t3;A8 B20 C11 D918、请看下面的代码。如果oneMethod抛出NullPointerException,则程序输出结果为( )。public void test( ) try oneMethod( ); System .out .println(“condition 1”); catch (ArrayIndexOutOfB
33、oundsException e) System .out .println(“condition 2”);catch (Exception e) System .out .println(“condition 3”); finally System .out .println(“condition 4”); Acondition 1 Bcondition 2 Ccondition 3 Dcondition 419.请看下面的代码public void test( ) try oneMethod( );System .out .println(“condition 1”); catch (Ar
34、rayIndexOutOfBoundsException e) System .out .println(“condition 2”);catch (Exception e) System .out .println(“condition 3”); finally System .out .println(“finally”);如果oneMethod正常运行,则程序输出结果为:Acondition 1Bcondition 2Ccondition 3Dfinally20.请看下面未完成的代码1.2. success = connect( );3. if(success=-1) 4. throw new TimedOutException( );5. 6.其中TimedOutException不是运行时间异常,则在第1行需要添加那一条语句来完成方法的声明:Apublic void method( )Bpublic void method( )throws ExceptionCpublic void method( )throws TimedOutExceptionDpublic void method( )throw TimedOutExceptionE. public throw TimedOutException void method( )
©2010-2025 宁波自信网络信息技术有限公司 版权所有
客服电话:4008-655-100 投诉/维权电话:4009-655-100