java单选
大学生java考试题及答案

大学生java考试题及答案一、单选题(每题2分,共20分)1. Java中,用于定义类的关键字是:A. classB. structC. interfaceD. enum答案:A2. 下列哪个选项不是Java的基本数据类型?A. intB. floatC. StringD. char答案:C3. 在Java中,用于捕获异常的关键字是:A. tryB. catchC. finallyD. throw答案:B4. 下列哪个选项不是Java的集合框架中的接口?A. ListB. MapC. SetD. Object答案:D5. Java中,用于定义接口的关键字是:A. interfaceB. classC. structD. enum答案:A6. 下列哪个选项不是Java的访问修饰符?A. publicB. privateC. protectedD. static答案:D7. 在Java中,下列哪个关键字用于定义一个方法?A. classB. methodC. functionD. void答案:D8. Java中,用于实现多线程的关键字是:A. threadB. synchronizedC. implementsD. extends答案:A9. 下列哪个选项是Java中的垃圾回收机制?A. JVMB. GCC. JITD. JITC答案:B10. 在Java中,下列哪个关键字用于定义一个包?A. packageB. importC. classD. interface答案:A二、多选题(每题3分,共15分)1. 下列哪些是Java的集合类?A. ArrayListB. LinkedListC. HashMapD. TreeMap答案:A, B, C, D2. 在Java中,下列哪些关键字用于控制流程?A. ifB. elseC. switchD. case答案:A, B, C3. 下列哪些是Java的异常处理关键字?A. tryB. catchC. finallyD. throw答案:A, B, C, D4. 在Java中,下列哪些是正确的继承方式?A. 单继承B. 多继承C. 接口实现D. 抽象类实现答案:A, C, D5. 下列哪些是Java的访问修饰符?A. publicB. privateC. protectedD. default答案:A, B, C, D三、判断题(每题2分,共10分)1. Java中的String类是可变的。
JAVA多线程期末考试题库单选题100道及答案解析

JAVA多线程期末考试题库单选题100道及答案解析1. 在Java 中,实现多线程有几种方式?()A. 2 种B. 3 种C. 4 种D. 5 种答案:B解析:实现多线程有三种方式:继承Thread 类、实现Runnable 接口、使用线程池的Callable 和Future 。
2. 以下哪个方法用于启动一个线程?()A. start()B. run()C. begin()D. execute()答案:A解析:调用线程对象的start() 方法启动线程,会自动调用run() 方法执行线程任务。
3. 以下关于线程和进程的说法,错误的是()A. 一个进程可以包含多个线程B. 线程是进程的执行单元C. 进程之间不能共享内存D. 线程之间可以独立运行答案:D解析:线程之间共享进程的内存空间,不是独立运行的。
4. 以下哪个方法可以让当前线程暂停一段时间?()A. sleep()B. wait()C. notify()D. yield()答案:A解析:Thread.sleep() 方法可以让当前线程暂停指定的时间。
5. 以下哪个方法用于线程间的等待/通知机制?()A. sleep() 和notify()B. wait() 和notify()C. yield() 和notifyAll()D. suspend() 和resume()答案:B解析:wait() 使当前线程等待,notify() 唤醒一个等待的线程,notifyAll() 唤醒所有等待的线程。
6. 以下关于线程同步的说法,错误的是()A. 可以使用synchronized 关键字实现线程同步B. 同步会降低程序的并发性C. 同步可以保证线程安全D. 所有方法都应该同步答案:D解析:不是所有方法都需要同步,只有在多个线程可能同时访问和修改共享资源时才需要同步。
7. 以下哪个不是线程的状态?()A. 就绪B. 运行C. 阻塞D. 结束E. 暂停答案:E解析:线程的状态包括就绪、运行、阻塞和结束。
java选择题库

11111111111111单选题第一套1-1-1-1下面的main()方法的定义哪些是正确的?()(A)public static void main(String args){}(B)public static void main(String[]){}(C)public static void main(String[] args){}(D)public static void MAIN(String[] xyz){}答案:C1-1-2-1用于定义简单数据类型的一组关键字是()(A)Student,float,main,public(B)byte,boolean,int,float(C)long,extends,float,double(D)class,float,short,import答案:B1-1-3-1以下变量定义中正确的是()(A)int I=123a (B)float f=7.8f(C)char c=’abc’ (D)String str=’d’答案:B1-1-4-1 for(;;)是( )(A)循环结构 (B)分支结构 (C)顺序结构答案:A1-1-5-1设类B和类C都不是抽象类,且类B是类C的父类。
下列声明对象x1的语句中不正确的是( )(A) B x1=new B() (B) B x1=new C()(C) C x1=new C() (D) C x1=new B()答案:D1-1-6-1设有对象x具有属性a则访问该属性的方法为()(A) a.x (B) a.x() (C) x.a (D) x.a()答案:C1-1-7-2定义变量如下:int i=18;long L=5;float f=9.8f;double d=1.2;String s=”123”;以下赋值语句不正确的是()(A)L=f+i (B)f=L+i(C)s=s+i (D)s=s+i+f+d答案:A1-1-8-2下面表达式的值的类型为()(int)(8/9.2*5)(A)short (B)int (C)double (D)float答案:B1-1-9-2 设数组Array由以下语句定义int Array=new int[10],则数组最后一个元素的正确引用方法为( )(A)Array[10] (B)Array[9] (C)array[10] (D)array[9]答案:B1-1-10-2 定义类A如下:()class A{int a,b,c;public void B(int x,int y,int z){ a=x;b=y;c=z;}}下面对方法B()的重载哪些是正确的()?(A)public void A(int x1,int y1,int z1){a=x;b=y;c=z;}(B)public void B(int x1,int y1,int z1){a=x;b=y;c=z;}(C)public void B(int x,int y){a=x;b=y;c=0;}(D)public B(int x,int y,int z){a=x;b=y;c=z;}答案:C1-1-11-2定义一个类Point,类中有两个double型变量x和y,对于其构造函数的声明不正确的是()(A) public Point(Point p ){…} (B) public Point(int x ){…}(C) public Point(int x,int y ){…} (D) Point Point(int x ){…}答案:D1-1-12-2 以public修饰的类如:public class Car{…} 则Car( )(A)可被其它程序包中的类使用(B)仅能被本程序包中的类使用(C)不能被任意其它类使用 (D)不能被其它类继承答案:A1-1-13-2下列说法哪个正确?(A)不需要定义类,就能创建对象(B)对象中必须有属性和方法(C)属性可以是简单变量,也可以是一个对象(D)属性必须是简单变量答案:C1-1-14-3覆盖与重载的关系是()(A)覆盖只有发生在父类与子类之间,而重载可以发生在同一个类中(B)覆盖方法可以不同名,而重载方法必须同名(C)final修饰的方法可以被覆盖,但不能被重载(D)覆盖与重载是同一回事答案:A1-1-15-3执行下列程序段后,b,x,y的值正确的是()int x=6,y=8;boolean b;b=x<y||++x= =--y;(A)true,6,8 (B)false,7,7(C)true,7,7 (D)false ,6,8答案:A单选题第二套1-2-1-1下面说法正确的是()(A)Java程序的源文件名称与主类(公共类)的名称相同,后缀可以是java或txt(B)JDK的编译命令是java(C)一个java源程序编译后可能产生几个字节码文件(D)在命令行运行编译好的字节码文件,只需在命令行直接键入程序名即可运行该程序答案:C1-2-2-1以下变量定义语句正确的是()(A)char c=”中” (B)double d=89L(C)byte b=512 (D)double a=8.6f答案:B1-2-3-1有关Java语言的说法中,哪种是错误的()(A) java是高级语言 (B) java是编译型语言(C)java是结构化设计语言(D) java是移植性强的语言答案:C1-2-4-1 JDK是( )(A)一种全新的程序语言(B)一种程序开发辅助工具(C)一种由Java写成的,并支持Java Applet的浏览器(D)一种游戏软件答案:B1-2-5-1关于构造函数的说法哪个正确?()(A)一个类只能有一个构造函数(B)一个类可以有多个不同名的构造函数(C)构造函数与类同名(D)构造函数必须自己定义,不能使用父类的构造函数答案:C1-2-6-1下列关于finally的说法正确的是?()(A)无论程序是否找到合适的例外控制器,都会去执行finally语句(B)finally语句应该放在所有例外控制器的最前面(C)如果程序在前面的例外控制器中匹配到了合适例外,就不再执行finally语句(D)如果程序在前面的例外控制器中匹配到了多个合适的例外,就不再执行finally语句答案:A1-2-7-2以下语句输出的结果是()String str=”123”;int x=4,y=5;str=str+x+y;System.out.println(str);(A)int 1239 (B)12345(C)回产生编译错误 (D)123+4+5答案:B1-2-8-2定义类头时可以使用的访问控制修饰符是()(A)public (B)abstract (C)final (D)private答案:A1-2-9-2下面的程序段输出的结果是()int i=1,b,c;int[] a=new int[3];b=a[i];c=b+i;System.out.println(c );(A)0 (B)2 (C)4 (D)1答案:D1-2-10-2 构造函数何时被调用?()(A)创建对象时(B)类定义时(C)使用对象的方法时(D)使用对象的属性时答案:A1-2-11-2抽象类与接口的区别在于:()(A)抽象类可以实现多重继承,而接口不行(B)抽象类不可以继承,而接口可以(C)抽象类中可以有非抽象的方法,而接口中只能有抽象方法(D)接口只是抽象类的另一种叫法答案:C1-2-12-2关于继承的说法正确的是:()(A)子类将继承父类所有的属性和方法。
java选择试题及答案

java选择试题及答案一、单项选择题(每题2分,共10分)1. 在Java中,下列哪个关键字用于定义一个接口?A. classB. interfaceC. abstractD. enum答案:B2. 下列哪个选项是Java语言中合法的变量名?A. 2numberB. _nameC. name$D. name答案:D3. 在Java中,下列哪种数据类型不是基本数据类型?A. intB. floatC. StringD. double答案:C4. 下列哪个关键字用于抛出异常?A. catchB. throwC. tryD. finally答案:B5. 在Java中,下列哪个方法用于将字符串转换为浮点数?A. parseInt()B. parseFloat()C. toInt()D. toFloat()答案:B二、多项选择题(每题3分,共15分)1. 下列哪些选项是Java中的访问修饰符?A. publicB. privateC. protectedD. static答案:A B C2. 在Java中,下列哪些关键字用于控制流程?A. ifB. elseC. switchD. break答案:A B C D3. 下列哪些选项是Java集合框架中接口?A. ListB. MapC. SetD. ArrayList答案:A B C4. 在Java中,下列哪些关键字用于定义方法?A. voidB. staticC. synchronizedD. final答案:A B C D5. 下列哪些选项是Java中的错误处理机制?A. tryB. catchC. finallyD. throw答案:A B C D三、判断题(每题1分,共5分)1. Java中的main方法必须声明为public static void。
答案:正确2. Java中的数组长度是可变的。
答案:错误3. Java中的类可以被继承,但接口不能被继承。
java单选题

D.实现ng.Thread类并重写start()方法
12.下列关于线程优先级的说法中,正确的是(C)
A.线程的优先级是不能改变的 B.线程的优先级是在创建线程时设置的
C.在创建线程后的任何时候都可以设置 D.B和C
A.8>>1 B.4>>>2 C.8 D.4
18.如果线程正处于运行状态,则它可能到达的下一个状态是(B)
A.只有终止状态 B.只有阻塞状态和终止状态
C.可运行状态,阻塞状态,终止状态 D.其他所有状态
19.在一个线程中调用下列方法,不会改变该线程运行状态的是(B)
C.Java编程时,要求应尽量不用公共变量 D.Java编程时,要求应尽量使用私有变量
33.JAVA语言中数据类型之间的自动类型转换是由优先关系从低级数据类型转换成高级数据类型,下面选项中自动类型转换优先级由低到高排列正确的是(A)
A.char->int->long->float->double B.int->char->long->float->double
36.Java中,int类型的字节数是__4_个字节。题型:填空题
37.私有成员变量的修饰符是:___ private____。
38.手工抛出异常的语句是____ throw ____语句。
39.在多线程程序设计中,如果采用继承Thread类的方式创建线程,则需要重写Thread类的____ run()____方法。
A.InputStream in=new FileInputStream("test.txt")
java单选题

单选题1、Java属于以下哪种语言?(C)A、机器语言B、汇编语言C、高级语言D、以上都不对2、在JDK安装目录下,用于存放可执行程序的文件夹是?AA、binB、jreC、libD、db3、下列Java命令中,哪一个可以编译HelloWorld.java文件?DA、java HelloWorldB、java HelloWorld.javaC、javac HelloWorldD、javac HelloWorld.java4、以下关于java命令作用的描述中,正确的是AA、它专门负责解析由Java编译器生成的.class文件B、它可以将编写好的Java文件编译成.class文件C、可以把文件压缩D、可以把数据打包5、下面关于配置path环境变量作用的说法中,正确的是(A )A、在任意目录可以使用javac和java命令B、在任意目录下可以使用class文件C、在任意目录可以使用记事本D、在任意目录下可以使用扫雷游戏6、下面关于path和classpath的说法中,错误的是(C)A、path用来指定 java 虚拟机(JVM) 所在的目录B、classpath用来指定我们自己所写的或要用到的类文件(.jar文件) 所在的目录C、在dos命令行中,classpath和path环境变量的查看与配置的方式不相同D、只要设置了classpath 这个环境变量系统就不会再在当前目录下查询某个类7、下面关于classpath的说法中,错误的是(D)。
A、classpath和path环境变量的查看与配置的方式完全相同。
B、为了让Java虚拟机能找到所需的class文件,就需要对classpath环境变量进行设置。
C、从JDK5.0开始,如果classpath环境变量没有进行设置,Java虚拟机会自动将其设置为“.”,也就是当前目录。
D、在命令行窗口中配置了classpath后,重新打开新命令行窗口依然生效8、下面哪种类型的文件可以在Java虚拟机中运行?(D)A、.javaB、.jreC、.exeD、.class9、阅读下段代码片段,选择正确的运行结果Apublic static void main(String[] args) {{int a = 1;System.out.print(a);}{int a = 2;System.out.print(a);}int a = 3;System.out.print(a);}A、123B、111C、121D、编译不通过10、下面选项中,哪个是短路与运算符( B )A、&B、&&C、|D、||11、关于表达式1234/1000 * 1000的运算结果,下列哪个选项是正确的(B )A、1234B、1000C、1234.0D、以上都不对12、下面的运算符中,用于执行除法运算是哪个?AA、/B、\C、%D、*13、以下哪个选项可以正确创建一个长度为3的二维数组(B )A、new int [2][3];B、new int[3][];C、new int[][3];D、以上答案都不对14、下列选项中,不属于比较运算符的是AA、=B、==C、<D、<=15、下列选项中,用于引入包的关键字是BA、classB、importC、packageD、static16、下列选项中,哪一个不能通过编译(D )A、byte a=1;B、short b=100;C、int c='a';D、long d=8888888888;17、下列选项中,哪一个是多行注释符号?(D )A、//* *//B、/* /*C、/ /D、/* */18、为了能让外界访问私有属性,需要提供一些使用( C )关键字修饰的公有方法。
java单选题库-博学谷
一、单选题1.Java属于以下哪种语言?()A. 机器语言B. 汇编语言C. 高级语言D. 以上都不对答案:C解析:Java是一门高级编程语言考察点:第一章 Java开发入门题目难度:★☆☆☆容易2.下列目录中,哪一个是用来存放JDK核心源代码的?A. lib目录B. src目录C. jre目录D. include目录答案:B解析:JDK核心源代码存放在src文件夹下考察点:第一章 Java开发入门题目难度:★☆☆☆容易3.下面命令中,可以用来正确执行HelloWorld案例的是()A. java HelloWorldB. java HelloWorld.javaC. javac HelloWorldD. javac HelloWorld.java答案:A解析:java命令负责运行编译后的.class文件,不需要文件后缀名。
考察点:第一章 Java开发入门题目难度:★☆☆☆容易4.下面关于配置path环境变量作用的说法中,正确的是()A. 在任意目录可以使用javac和java命令B. 在任意目录下可以使用class文件C. 在任意目录可以使用记事本D. 在任意目录下可以使用扫雷游戏答案:A解析:path环境变量的作用是在任意目录下都可以使用javac和java命令。
考察点:第一章 Java开发入门题目难度:★☆☆☆容易5.下列选项中,可以正确配置classpath的命令是()A. set classpath =C:\Program Files\Java\jdk1.7.0_15\binB. set classpath : C:\Program Files\Java\jdk1.7.0_15\binC. classpath set =C:\Program Files\Java\jdk1.7.0_15\binD. classpath set : C:\Program Files\Java\jdk1.7.0_15\bin答案:A解析:配置classpath的命令是set classpath=xxx,并且等于号两边不要有空格。
java考试题及答案
java考试题及答案一、选择题(每题2分,共20分)1. 在Java中,以下哪个关键字用于定义一个类?A. classB. interfaceC. enumD. struct答案:A2. Java中的main方法的返回类型是什么?A. voidB. intC. StringD. boolean答案:B3. 下列哪个是Java的原始数据类型?A. StringB. intC. ArrayListD. Object答案:B4. 在Java中,哪个关键字用于实现多态?A. newC. implementsD. override答案:D5. 以下哪个是Java集合框架中的接口?A. ListB. SetC. MapD. All of the above答案:D6. Java中的异常处理是通过哪两个关键字实现的?A. try and catchB. if and elseC. for and whileD. switch and case答案:A7. 以下哪个是Java的访问修饰符?A. publicB. staticC. finalD. synchronized答案:A8. 在Java中,哪个关键字用于定义一个接口?B. interfaceC. packageD. enum答案:B9. Java中的String类是不可变的,这意味着什么?A. 字符串值不能被修改B. 字符串对象不能被实例化C. 字符串不能被用作数组D. 字符串不能被用作方法参数答案:A10. 在Java中,哪个关键字用于定义一个枚举类型?A. enumB. classC. interfaceD. struct答案:A二、简答题(每题5分,共20分)1. 简述Java中的垃圾回收机制。
答案:Java中的垃圾回收机制是一种自动内存管理功能,它会自动检测不再使用的对象,并释放它们占用的内存。
垃圾回收器会周期性地运行,寻找那些没有被任何引用指向的对象,然后回收它们占用的内存空间。
java单选题题目
1. The name of a Java source file (d)(d) must be the same as the class it defines, respecting case2. Which method must exist in every Java application? (a)(a) main1. Given the following code, how many tokens will be output? (b)StringTokenizer st = new StringTokenizer("this is a test");while (st.hasMoreTokens()) {stdOut.println(st.nextToken() );}(b) 42. Classes from which of the following packages are implicitly imported into every Java program? 答案:(d)(d) ng3. What is the name of the wrapper class for the type int? (d)(d) Integer4. Classes from which of the following packages are implicitly imported into every Java program?(c)(c) ng5. The term wrapper classes refers to (a)(a) a collection of Java classes that "wrap" Java primitive types6. What will be output caused by the execution of the following Java program segment? (c) String name = "Elvis";System.out.print(name + "was here");(c) Elviswas here1. What will be output when the following Java program segment is executed? (c)int x = 5;int y = 2;System.out.println(x + y);(c) 72. A difference between the methods print and println of the class java.io.PrintWriter is that (a)(a) println appends a new line to the end of its output, but print does not3. Consider the following Java program segment. (c)int x = 5;int y = 2;System.out.println(x + "1" + y);Which of the following statements is true about the program segment?(c) The output caused by the code will be 512.1. All Java exception classes are derived from the class (a)(a) ng.Throwable2. In Java, exceptions that are not handled are passed up the (b)(b) call stack3. What is the right way to handle abnormalities in input on Java? (d)(d) By handling these problems by providing exception handlers4. Consider the following Java program segment.import java.io.*;public class SomeClass{public void x() {throw new RuntimeException("Exception from x");}public void y(){throw new IOException("Exception from y");}}Which of the following is true concerning the definitions for the methods x and y? (a)(a) x has a legal definition, but y has an illegal definition.1. Which of the following statements is true of the conventions outlined by Sun Microsystems in the document entitled Code Conventions for the Java Programming Language? (d)They define a standard interface definition language that must be used for all Java classes.They provide recommendations intended to make source code easier to read and understand. They describe one mechanism for network communication between Java and C++ programs. (d) II onlyFeedback: See section 1.1.6, subsection "CodeConvTOC" and section 1.1, subsection "Why Have Code Conventions," in the course notes.2. According to the Java code conventions, files that contain Java source code have the suffix _____, and compiled bytecode files have the suffix _____. (d)(d) .java, .classFeedback: See section 1.1.6, subsection "CodeConvTOC" and section 2.1, subsection "File Suffixes," in the course notes.3. According to the document entitled Code Conventions for the Java Programming Language, file suffixes used by Java software include which of the following? (b).obj.class.h(b) II only1. Which of the following patterns of characters opens a Javadoc comment block? (b)(b) /**1. After a typical debugger encounters a breakpoint, the programmer using the debugger may perform which of the following actions? (a)Examine the values of variables in the halted programExecute the current lineResume execution of the halted program(a) I, II, and III2. In a typical source-code debugger, a programmer can set a _____ to cause a program to stop executing at a particular line of code. (c)(c) breakpoint3. A stack trace is (b)(b) a sequence of method calls4. A tool that allows programmers to execute lines of a program one line at a time in order to help locate the source of a program's errors is known as a(n) (b)(b) debugger1.According to Javadoc convention, the first sentence of each Javadoc comment should be (c) (c) a summary sentence of the declared entryFeedback: See /j2se/javadoc/writingdoccomments/index.html#format for more information.1. In a UML class diagram's representation of a class, the top, middle, and lower rectangular compartments respectively describe the _____ of the class. (c)(c) name, attributes, and methods2. UML class diagrams can describe which of the following? (b)The internal structure of classesRelationships between classes(b) I and II1. Consider the following UML class diagram.According to the diagram, instances of the class named _____ have references to instances of the class named _____. (a)(a) A, B2. Consider the following UML class diagram.According to the diagram, which of the following statements is true? (a)(a) ClassA is composed of one instance of ClassB and one or more instances of ClassC.3. A binary association is said to exist between two classes when (a)(a) an object of one class requires an object of the other class4. The multiplicity of an association between two classes indicates the number of (a)(a) instances of one class that can be associated with an instance of the other class5. Which of the following is true about association and aggregation in UML class diagrams? (c)(c) Aggregation is a special form of association.1. A collection typically models a _____ relationship. (b)(b) one-to-many2. Consider the following UML class diagram. (c)The diagram describes a(c) self-containing class3. Consider the class described by the following diagram:If the class represents an employee and the boss attribute refers to the employee's boss, which of the following statements is (are) true? (c)Many employees can have the same boss.One employee can have many bosses.(c) I only4. Consider the following UML class diagram.Which of the following is (are) true about the system described by the diagram? (d)An instance of Picture can contain a collection of instances of the class Shape.An instance of Shape can contain a collection of instances of the class Picture.(d) I only5. If a class has an association with itself, then the class contains (b)(b) an attribute that references an object of the same class1. An object model describes which of the following? (c)Attributes of classesMethods of classesRelationships between classes(c) I, II, and III2. In an object model, the data that an object is responsible for maintaining are represented by (b)(b) attributes1. A relationship that exists between two specific instances of an object is known as a(n) (b)(b) linkFeedback: See Chapter 5, page 114, in the course textbook.2. The static model of a software system typically includes which of the following? (b) Attributes of classesActions that occur between classesStructural relationships between classes(b) I and III onlyFeedback: See Chapter 10, page 213, in the course textbook.3. Consider the following UML class diagram.According to the diagram, which of the following statements is (are) true? (c)ClassB is a specialization of ClassA.ClassA is a generalization of ClassC.ClassC is involved in a self-containment loop.(c) I, II, and III4. When using noun-phrase analysis to model a software system, which of the following should typically be eliminated from the list of potential classes? (a)References to the software system itselfNouns that imply roles between objectsSynonyms to other nouns in the list(a) I, II, and IIIFeedback: See Chapter 10, page 216-219, in the course textbook.1. The term class variable is a synonym for (c)(c) a static data field1. Which is the Java keyword used to denote a class method? (c)(c) static2. Which of the following statements about class variables in Java is not true? (c)(c) All objects have their own copy of the class variable defined in the instantiated class.3. Which of the following categorizations can be applied to both the data fields and the methods ina Java class? (a)(a) static and non-static1. What is used to indicate that a method does not return a value? (c)(c) the keyword voidFeedback: See chapter 4 of the text.2. The return type for a method that returns nothing to its caller is (c)(c) voidFeedback: See chapter 4 of the text.3. If a class contains a constructor, that constructor will be invoked (c)(c) each time an object of that class is instantiatedFeedback: See chapter 4 of the text.4. If the method int sum(int a, int b) is defined in a Java class C, which of the following methods cannot coexist as a different method in class C? (b)(b) int sum(int x, int y)Feedback: See chapter 5 of the text.5. From within a child class, its parent class is referred to via the keyword (d)(d) superFeedback: See chapter 5 of the text.6. When a subclass defines an instance method with the same return type and signature as a method in its parent, the parent's method is said to be (a)(a) overriddenFeedback: See chapter 5 of the text.7. Consider the following Java class definitions.public class Object1 {protected String d(){return "Hi";}}public class Object2 extends Object1 {protected String d(){return super.d();}}Which of the following statements is (are) true regarding the definitions? (d)Class Object2 inherits from class Object1.Class Object2 overrides method d.Method d returns equivalent results when executed from either class.(d) I, II, and IIIFeedback: See chapters 5 and 13 of the text.8. Consider the following Java program segment.import java.io.*;public class Test {public Test( ) {System.out.println("default");}public Test( int i ) {System.out.println("non-default");}public static void main(String[] args) {Test t = new Test(2);}}Which of the following will be output during execution of the program segment? (a)(a) The line of text "non-default"Feedback: See chapter 13 of the text.9. Which of the following statements about constructors in Java is true? (b)(b) A class can define more than one constructor.Feedback: See chapter 13 of the text.10. Which is a Java access modifier used to designate that a particular data field will not be inherited by a subclass? (c)(c) privateFeedback: See chapter 13 of the text.1. Consider the following Java program segment.int[] arr;arr = new int[3];arr[2]=19;arr[1]=17;arr[0]=15;Which of the following Java statements is syntactically correct and semantically identical to the program segment? (b)(b) int[] arr= {15, 17, 19};2. Consider the Java program below.public class Arr{public static void main(String[] args) {int[] a = {1, 2, 3};System.out.println(a[1]);System.out.println(a[3]);}}Which of the following is true about the result of executing the program? (c)(c) The number 2 is printed and a run-time exception terminates execution.3. If the length of a particular array is the value of LIMIT, what is the index of the last item in that array? (d)(d) LIMIT - 14. Legal Java statements to initialize an array reference include which of the following? (b)int[] aobj = {0, 1, 2};int[4] aobj = {0, 1, 2};int[] aobj = new int[3];(b) I and III only5. A Java array that contains n components will be indexed from _____ through _____. (b)(b) 0, n-16. Consider the following Java program segment.String[] str = {"Three","Two","One"};for (int i = 0; i < str.length; ++i) {System.out.println(str[i]+"/");}What will be output upon execution of the program segment? (d)(d) Three/Two/One/7. Regarding the following declaration, what is the index of the element containing 45? (d)int[] numbers = {-1, 45, 6, 132};(d) 11. Consider the following method call, where c is an instance of the class java.util.ArrayList.c.size();This method call returns the number of (c)(c) elements in the ArrayList represented by c2. An object that contains methods that traverse a collection linearly from start to finish is known as a(n) (a)(a) iterator3. Which of the following statements is not true of the class java.util.ArrayList? (b)(b) Once an object is inserted into an instance of ArrayList, it can never be removed.4. In which of the following ways can items be added to a collection implemented by java.util.ArrayList? (b)Items can be inserted at the beginning of the collection.Items can be inserted between two existing items in the collection.Items can be appended to the end of the collection.(b) I, II, and III5. Which of the following methods is (are) provided by java.util.Iterator? (d)next, which causes an iterator to return the next item in its iterationremove, which can remove an item from a collection associated with an iterator(d) I and II6. The class java.util.ArrayList implements a collection that (c)(c) can grow to accommodate new items1. Which of the following statements is (are) true about any abstract method in Java? (b)It contains no definition.It cannot be declared public.(b) I only2. Which of the following statements is (are) true in Java? (b)Classes that contain abstract methods must be declared abstract.Classes that contain protected methods must be declared abstract.(b) I only3. The subclass of an abstract class must (c)(c) be abstract or implement all of the parent's abstract methods1. Which of the following statements about Java classes is (are) accurate? (c)A class may have only one parent.Two or more classes may share a parent.(c) I and II2. Consider the following Java program fragment.public void drive(Vehicle v) {...}...drive(obj);The method call drive(obj) is valid if obj is which of the following? (a)A descendent of class VehicleAn ancestor of class VehicleAn object of class Vehicle(a) I and III only1. Which of the following statements is (are) true about interfaces in Java? (d)Interfaces can extend other interfaces.Interfaces can contain data fields.(d) I and II2. Which of the following statements is (are) true in Java? (d)An abstract class may contain data fields.Interfaces may contain data fields.(d) I and II3. Which of the following statements is (are) true about inheritance in Java? (c)A class can extend more than one abstract class.A class can implement more than one interface.(c) II only4. Which of the following statements is (are) true about all data fields in an interface in Java? (c) They are implicitly public.They are implicitly final.They are implicitly static.(c) I, II, and III5. Which is the Java keyword that denotes the use of an interface? (d)(d) implements6. Which of the following statements is (are) true in Java? (b)All of the methods in an abstract class must be abstract.All of the methods in an interface must be abstract.(b) II only7. In Java, all methods in an interface must be _____ and _____. (b)(b) public, abstract8. Data fields in an interface implicitly have _____ access in Java. (a)(a) public1. A design pattern is typically used to (c)(c) describe a practical solution to a common design problem1. Consider the following definition of a Java class.public class C {private static C instance = null;private C() {}public static C getInstance() {if (instance == null) {instance = new C();}return C;}}This class is an example of the design pattern (d)(d) Singleton2. The constructor of a class that adheres to the Singleton design pattern must have _____ visibility. (a)(a) private1. In which of the following design patterns is a family of algorithms encapsulated into individual but interchangeable classes? (a)(a) Strategy2. The Strategy design pattern is likely to be useful when implementing which of the following?(a) An application that offers several alternate sorting algorithmsA simple class to store the address of an organization of which only one instance can be instantiated(a) I only1. Consider the following Java program segment. (a)PrintWriter fileOut = new PrintWriter(new FileWriter("output.txt"));If the file output.txt already exists, which of the following events will occur when the program segment is executed?(a) The existing contents of output.txt will be erased.2. If a file opened for reading does not exist, which of the following events will occur in Java? (a)(a) A FileNotFoundException will be raised.1. (1)The model part of the Model-View-Controller (MVC) paradigm embodies the (a)(a) abstract domain knowledge of an application(2)The view part of the Model-View-Controller (MVC) paradigm is the (b)(b) way in which the abstract domain knowledge of an application is presented to the userFeedback: See Chapter 16, page 474, in the course textbook.2. Which of the following is true regarding the controller part in the Model-View-Controller (MVC) paradigm? (a)(a) The controller is the automatic mechanism by which the user interface is displayed and by which events are communicated between the model and the view.Feedback: See Chapter 16, page 475, in the course textbook.3. In Java, the default layout manager for a JPanel component is (c)(c) FlowLayoutFeedback: See Chapter 16, page 494, in the course textbook.4. What is the number of regions into which the BorderLayout in Java subdivides a container? (a)(a) 5Feedback: See Chapter 16, page 494, in the course textbook.5. Which of the following is (are) true regarding event handling in Java? (a)When a GUI component is created, the component automatically has the ability to generate events during user interaction.Each Listener object must be registered with the specific component object or objects for which the Listener object is to respond.(a) I and IIFeedback: See Chapter 16, page 523, in the course textbook.6. Which of the following is a Java event that is generated when a JButton component is pressed? 答案:(b)(b) ActionEventFeedback: See Chapter 16, page 525, in the course textbook.7. The ListSelectionEvent class and ListSelectionListener interface are available in the _____ package of Java. (b)(b) javax.swing.eventFeedback: See Chapter 16, page 525, in the course textbook.8. Which of the following is a Java event that is generated when the close button on a JFrame component is pressed? (b)(b) WindowEventFeedback: See Chapter 16, page 534, in the course textbook.9. In Java, what is the signature of the method in the WindowListener interface where code is to be added to end a program when the close button is pressed? (d)(d) void windowClosing (WindowEvent we)Feedback: See Chapter 16, page 537, in the course textbook.10. What is the signature of the method specified in the Java ListSelectionListener interface? (b)(b) void valueChanged (ListSelectionEvent lse)Feedback: See Chapter 16, page 540, in the course textbook.Given the following code, what value will be output by the last statement?StringTokenizer st = new StringTokenizer("this is,a,test of tokens", ",");String s;int count = 0;while (st.hasMoreTokens()){ s = st.nextToken();++count;}stdOut.println(count);正确答案: C. 3The name of a Java source file正确答案: A. must be the same as the class it defines, respecting caseWhich of the following statements is (are) true about the use of an asterisk (*) in a Java import statement?It does not incur run-time overhead.It can be used to import multiple packages with a single statement.It can be used to import multiple classes with a single statement.正确答案: B. 1 and 3 onlyConsider the following Java program segment.int x = 5; int y = 2; System.out.println(x + "1" + y);Which of the following statements is true about the program segment?正确答案: A. The output caused by the code will be 512.What is the right way to handle abnormalities in input on Java?正确答案: C. By handling these problems by providing exception handlersThe term wrapper classes refers to正确答案: A. a collection of Java classes that "wrap" Java primitive typesFrom within a child class, its parent class is referred to via the keyword正确答案: C. superWhat is used to indicate that a method does not return a value?正确答案: B. the keyword voidWhich of the following statements about constructors in Java is true?正确答案: D. A class can define more than one constructor.When a subclass defines an instance method with the same return type and signature as a method in its parent, the parent's method is said to be正确答案: A. overriddenIf a class contains a constructor, that constructor will be invoked正确答案: B. each time an object of that class is instantiatedWhich is a Java access modifier used to designate that a particular data field will not be inherited by a subclass?正确答案: C. privateConsider the following Java class definitions.public class Object1 {protected String d(){return "Hi";}}public class Object2 extends Object1{protected String d(){return super.d();}}Which of the following statements is (are) true regarding the definitions?Class Object2 inherits from class Object1.Class Object2 overrides method d.Method d returns equivalent results when executed from either class.正确答案: C. I, II, and IIIWhen a subclass defines an instance method with the same return type and signature as a method in its parent, the parent's method is said to be正确答案: A. overriddenIf the method int sum(int a, int b) is defined in a Java class C, which of the following methods cannot coexist as a different method in class C?正确答案: C. int sum(int x, int y)import java.io.*;public class Test {public Test( ) {System.out.println("default");}public Test( int i ){System.out.println("non-default");}public static void main(String[] args) {Test t = new Test(2);}}Which of the following will be output during execution of the program segment?正确答案: C. The line of text "non-default"Consider the Java program below.public class Arr{public static void main(String[] args){int[] a = {1, 2, 3};System.out.println(a[1]);System.out.println(a[3]);}}Which of the following is true about the result of executing the program?正确答案: C. The number 2 is printed and a run-time exception terminates execution.Which of the following methods is (are) provided by java.util.Iterator?next, which causes an iterator to return the next item in its iterationremove, which can remove an item from a collection associated with an iterator正确答案: C. I and IIWhich of the following statements is not true of the class java.util.ArrayList?正确答案:C. Once an object is inserted into an instance of ArrayList, it can never be removed.Regarding the following declaration, what is the index of the element containing 45?int[] numbers = {-1, 45, 6, 132};正确答案: D. 1String[] str = {"Three","Two","One"};for (int i = 0; i < str.length; ++i){ System.out.println(str[i]+"/"); }What will be output upon execution of the program segment?正确答案: C. Three/Two/One/Consider the following method call, where c is an instance of the class java.util.ArrayList.c.size();This method call returns the number of正确答案: C. elements in the ArrayList represented by cConsider the following Java program segment.int[] arr; arr = new int[3]; arr[2]=19; arr[1]=17; arr[0]=15;Which of the following Java statements is syntactically correct and semantically identical to the program segment?正确答案: D. int[] arr= {15, 17, 19};If the length of a particular array is the value of LIMIT, what is the index of the last item in that array?正确答案: A. LIMIT - 1The class java.util.ArrayList implements a collection that正确答案: D. can grow to accommodate new itemsAn object that contains methods that traverse a collection linearly from start to finish is known as a(n)正确答案: C. iteratorUML class diagrams can describe which of the following?1、The internal structure of classes2、Relationships between classes错误!未找到引用源。
JAVA单选
1:5、执行如下语句之后,输出的结果是( )。
4.02:26、定义类时,不可能用到的保留字是( )。
5.无3:1、在下列说法中,选出最正确的一项是( )。
1.Java语言是以类为程序的基本单位的4:85、下面哪一个是符合Java语言语法的语句?()4.int a=0;int b=2;int 12=7;a =a+12=c+b;5:11、在创建Applet应用程序时,需要用户考虑的问题是( )。
2.绘制的图形在窗口中的位置6:108、下列说法中,错误的一项是( )。
2.打开一个文件时不可能产生IOException7:119、下列说法中,错误的一项是( )。
1.Swing构件可以直接添加入顶层容器之中8:42、下列关于short类型数据的说法中正确的一个是( )。
4.short类型存储数据的顺序是先高后低9:28、下列说法中,不止确的一项是( )。
2.类的方法只能由public修饰10:120、下列不属于java.awt包中的基本概念的一项是( )。
3.线程11:110、下列哪一个类实现了线程组?()2.java.1ang.ThreadGroup12:41、现在有一个int类型的变量a和一个char类型的变量b,关于它们之间类型转换的说法中,正确的一个是( )。
1.a必须性制转换为b13:109、下列哪一个是Pattern类的方法?()3.start()14:55、下列哪一个是合法的char类型数据( )?1.’\14l’15:33、下列描述中不正确的一项是( )。
4.Java语言和c++一样有指针16:111、要实现完全定制串行化,串行化类必须实现的接口是( )4.Extenalizable17:5、下列选项中,属丁JVM执行过程中的特点的一项是( )。
3.异常处理18:74、设有定义int x=5;则执行以下语句后,x的值为( )。
x+=x+5;2.1519:93、在使用interface声明一个接口时,只可以使用哪一个修饰符修饰该接口?"()4.ch4 package;20:100、下列描述中,哪一项不属于finally语句应陔执行的功能( )?3.分配资源21:40、现有2个byte类型的变量bb=126、bb2=5,当执行bbl=(byte)(bb+bb2);语句之后,bb的值应该是( )。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
章节题干A B 1线程是Java程序的( )机制。
检查解释执行1下面对于Java和C++的区别,描述不正确的的是( )。
Java没有指针而C++有Java具有跨平台性而C++没有1Java作为编程语言,( )特点是Java不具备的。
利用了面向对象的技术基础可移植性1Java作为编程语言,( )是最基本的元素。
对象方法1JDK中,用于编译程序的工具是( )。
Javac Java1在创建Applet的应用程序时,用户应考虑的问题是()。
窗口如何创建绘制的图形在窗口中的位置1JDK安装完成后,主要的命令如Javac、Java等都存放在( )文件夹中。
bin jre1下面选项不是表达式语句的是( )。
c++;a=b+c;1下面说法不正确的是( )。
表达式可以是其他表达式的操作数单个常量或变量可以作为表达式1执行下列程序,输出结果为( )。
public class B{public static void main(String[] args){int x=5;double y=10.5f;float z=(float)(x*y);System.out.println(z);}}50.052.01执行下列代码段之后,输出结果为( )。
public class H{public static void main(String[] args){int sum=2,a=3,b=5,c=7;while (a<b){while (b!=c){sum+=b;b++;}b=5;a++;}System.out.println(sum);}}23241下面类变量和实例变量的叙述中描述错误的是()。
实例变量是类的成员变量类变量第一次用到时被初始化,以后创建其他对象是就不再进行初始化下面( )修饰符可以使一个类中的成员变量能被外部类调用。
public protected1定义类头时,不可以放在类名前面的关键字是()。
public abstract1下面关于类的说法中,错误的是( )。
类是经过抽象的共有属性的集合类是Java程序的核心和本质1下面有关变量调用的语句正确的是( )。
public class Number{int a=2;float b=12;static int c=13;public static void main(String[] args){Number one=new Number();}}one.a Number.a1设Test为定义的类,下面声明类Test对象a的语句正确的是( )。
Testa=Test();publicTest a;1定义抽象类的关键字是( )。
final public1定义一个公有double型符号常量PI,下面的语句中正确的是( )。
publicfinaldoublePI;publicfinalstaticdoublePI=3.14159;1有一个类B,下面是它的构造方法的声明,正确的是( )。
voidB(int x){}B(int x){}1main 方法是 Java Application 程序执行的入口点,关于 main 方法的方法头以下哪项是合法的()publicstatic voidmain ()publicstatic voidmain (Stringargs[] )1下列代码中,将引起一个编译错误的行是1)public class Test{2) int m,n;3) public Test(){}4) public Test(int a){m=a;}5) public static void main(String args[]){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) }第3行第5行1编写AWT图形用户程序时,一定要用import的语句是( )。
importjava.awt;importjava.awt.*;1下列说法不正确的一项是( )。
组件是一个可视化的能与用户在屏幕交互的对象组件能独立显示出来1下列说法中错误的一项是( )。
TextArea可以显示多行多列的文本TextArea可以显示单行多列的文本1下面关于框架Frame的说法错误的一项是( )。
若要显示框架,必须对其设置尺寸,否则尺寸为0,不会显示。
对于框架来说,可以调用方法setVisible()来显示框架1下列哪个类声明语句是正确的( )abstractfinalclass H1{…}abstractprivatemove(){…}1哪种循环在条件表达式被计算之前至少执行循环体语句一次。
( )do-while循环for循环1下列叙述中,错误的是。
( )父类不能替代子类父类包含子类1时间处理机制能够让图形界面响应用户的操作,主要包括( )。
事件处理事件源1下列说法中,不正确的一项是( )。
事件源与事件监听器可以位于同一个类中事件适配器类同接口一样,必须实现所有的方法1TextField的事件监听器接口是( )。
ChangeListenerItemListener1Swing采用的设计规范是( )。
视图-模式-控制器控制器-模式-视图1抽象窗口工具包( )是Java提供的建立图形用户界面GUI的开发包。
Java.long Java.io1关于使用Swing的基本规则,下列说法正确的是()。
Swing组件可直接添加到顶级容器中要尽量使用非Swing的重量级组件1下列Component类的方法中,用于组件可见性的是( )。
updata( )paint(Graphics g)1下列说法中,不正确的一项是( )。
Swing组件可以设置一个或多个边框Swing的按钮组件上可以使用图标1下列有关MVC体系结构的说法中错误的一项是( )。
模型是指定的逻辑表示方法视图是模型的可视化表示方法1要表示表格数据,需要继承下列( )类。
Jtable TableMode l1关于Graphics类画线方法drawLine(int a,intb,int c,int d)的说法中,错误的是( )(a,b)为线段的起点坐标a、c表示线段的起点与终点的Y坐标1以下所列方法中,( )为Graphics类所提供的绘制文本的方法。
drawString( )drawBytes( )1关于drawPolygon()与fillPolygon()两种方法的说法中,错误的说法是( )前者以线条方式画多边形,后者以填充方式画多边形fillPolygon()方法采用奇偶规则来充填多边形1Java的图形坐标系是以( )为坐标原点的。
坐标平面的左上角坐标平面的左下角1关于Applet,下面说法( )是错误的。
Applet也可以是一个ApplicationApplet就是一个Application,Application包含Applet1关于Applet的生命周期正确的说法是( )。
init()方法在start()方法之后执行init()方法可执行多次1Applet程序的顶级容器是( )。
Japplet Jframe 1当小程序窗口需要重画时,将调用( )方法。
start()init() 1以下方法用于定义线程执行体的是( )。
start()init()线程Thread类提供表示线程优先级的静态变量,代表普通优先级的静态常量是( )。
MAX_PRIORITYMIN_PRIORITY1下列不是用来捕获处理异常的关键字是( )。
throws try1以下( )方法可以获取指定URL的协议名。
publicStringgetProtocol()publicStringgetHost()1以下( )方法可以实现与指定的URL建立连接并返回InputStream类的对象,以从这一连接中读取数据。
readline()read()1以下( )方法可以获取指定的URL位置的图象。
showDocument(URLurl)getAudioClip(URLurl)1以下( )是Java的IP地址封装类URL类InetAddre ss类1以下( )方法可以获得主机名字或一个具有点分形式的数字IP地址。
getFile()getQuery()1一个Socket由( )唯一确定。
一个IP地址和一个端口号一个IP地址和一个主机名1一个URL地址由以下( )组成。
文件名和主机名主机名和端口名1http服务的端口号为( )。
8021C D E F答案难度图片并行并发D中Java支持多继承而C++只支持但继承以上说法都对C中独立于硬件结构多重继承D中包接口A中Javap Javadoc A中程序的框架事件的处理C中doc include A中a+=b;System.out.println("A")D中表达式和表达式语句是一样的表达式的类型可以和操作数的类型不一样C中50.552.5D中2526B中实例变量在每次创建时都被初始化实例变量是用static修饰的成员变量D中private没有修饰符A中final static D中类是对象的模板,而类对象则是类实例化结果在面向对象的编成语言中,类不是一个独立的程序单位D中number.a Number.one A中Test a=new Test();publicTest a=newTest();D中abstract protected C中public final static double PI;publicstaticdoublePI=3.14159;A中void b(int x){ }b(int x){}B中public static int main (String [] arg )publicvoidmain (Stringarg[] )B中第6行第10行A中import javax.awt;importjavax.swing;B中一个文本框可以是一个组件组件必须放在容器里才能正确显示D中在单行文本输入区中按下Enteer键会触发ActionEvent 事件单行文本区可以通过方法setEditable(Boolean)设置只读属性,但是多行文本区却不能D中对于框架来说,一定要调用show()方法,否则框架不显示对框架添加组件,需要加在其内容面板上C中protected private number;publicabstractclass Car{…}D中while循环 以上都不是A中子类能够替代父类子类继承父类B中事件以上都是D中一个对象可以监听一个事件源上的多个事件一个类可以实现监听器接口B中WindowLiten er ActionListenerD中模式-视图-控制器控制器-视图-模式C中Swing AWT D中Swing的JButton不能直接放到Frame上以上说法都不对D中setVisible(Boolean b)repaint( )C中Swing组件可以使用键盘代替鼠标操作Swing中需要手工编写缓冲区D中控制器用于指定用户输入的处理机制MVC体系结构用于AWT中D中JTableModel AbstractTableModelD中(c,d)为线段的终点坐标b、d表示线段的起点与终点的Y坐标B中drawChars()以上都是D中drawPolygon ()方法画的图形一定是封闭的两种方法都定义在java.awt.Graphics类中C中坐标平面的右上角坐标平面的右下角A中Applet可以在浏览器中执行Applet不能直接用Java解释器执行B中stop()方法在Applet退出时被调用,只调用一次stop()方法在Applet不可见时被调用,可以被调用多次D中Jdialog Jpanel D中paint()stop()C中run()main()C中NORM_PRIORI T NORMAL_PRIORITC中catch finally A中publicfinal Object getContent( )public intgetPort()A中openStream()new URL()C中getImage(UR L url)showStatus(Stringstr)C中Applet类Socket类B中getHostName()getPath()C中一个主机名和一个端口号一个端口号A中IP地址和主机名协议名和资源名D中23120A中。