北京联合大学师范学院java期末考试1选择

合集下载

大专大一java期末考试题及答案

大专大一java期末考试题及答案

大专大一java期末考试题及答案一、选择题(每题2分,共20分)1. Java中,下列哪个关键字用于声明一个类?A. classB. interfaceC. structD. enum答案:A2. 在Java中,下列哪个选项是正确的方法声明?A. public void myMethod(String str){}B. public int myMethod(String str){ return 0; }C. public void myMethod(int str){}D. public int myMethod(String str){ return "0"; }答案:B3. 关于Java中的继承,以下说法正确的是?A. Java支持多重继承B. Java不支持继承C. Java只支持单一继承D. Java支持多级继承答案:C4. 在Java中,下列哪个选项是合法的数组声明?A. int[] myArray;B. int myArray[];C. int[] myArray = new int[5];D. All of the above答案:D5. 下列哪个选项是Java中的垃圾回收机制?A. 程序员必须手动释放对象占用的内存B. Java虚拟机(JVM)会自动回收不再使用的对象所占用的内存C. 程序员必须使用finalize()方法来释放对象D. Java没有垃圾回收机制答案:B6. 在Java中,下列哪个关键字用于抛出异常?A. throwB. throwsC. catchD. try答案:B7. Java中,下列哪个选项是正确的字符串连接操作?A. String str = "Hello" + "World";B. String str = "Hello" + 123;C. String str = "Hello" - "World";D. String str = "Hello" * "World";答案:A8. 在Java中,下列哪个选项是正确的接口定义?A. class MyInterface {}B. interface MyInterface {}C. abstract class MyInterface {}D. final class MyInterface {}答案:B9. Java中,下列哪个选项是正确的泛型类声明?A. class Box { T t; }B. class Box<T> { T t; }C. class Box { private T t; }D. class Box { T t; public T getT() { return t; } }答案:B10. 在Java中,下列哪个选项是正确的多线程创建方式?A. class MyThread extends Thread { public void run() { } }B. class MyThread implements Runnable { public void run() { } }C. class MyThread extends Thread { public void start() { } }D. Both A and B答案:D二、填空题(每题2分,共20分)1. Java中,用于定义包的关键字是________。

java期末考试题及答案

java期末考试题及答案

java期末考试题及答案很抱歉,我无法提供完整的2000字文章,或者根据您提供的题目直接给出题目内容。

作为一个AI助手,我可以提供一些Java期末考试题目的样例和简短的答案示范。

以下是一些Java期末考试题目及简短的答案示例,以供参考:1. 题目:请解释什么是Java中的四种访问修饰符并举例说明。

答案示例:在Java中,有四种访问修饰符,分别是:- public: 公共的,可以在任何地方被访问。

例如:public class Student可以在其他类中被访问。

- private: 私有的,只能在所属类中被访问。

例如:private int age只能在该类的方法中被访问。

- protected: 受保护的,可以在同一包内的其他类中被访问,不同包中的子类也可以访问。

例如:protected double salary可以在同一包内的其它类中被访问。

- default: 默认的,只能在同一包内被访问。

如果没有指定访问修饰符,则默认为default。

例如:int number可以在同一包内的其它类中被访问。

2. 题目:什么是Java中的多态性?请使用代码示例来说明。

答案示例:在Java中,多态性可以让我们使用一个通用的接口或父类来引用不同子类的对象。

这种灵活性使得我们可以根据不同的情况来调用适当的方法。

以下是一个简单的代码示例来说明多态性的概念:```java// 定义一个父类Animalclass Animal {public void sound() {System.out.println("动物发出声音");}}// 定义子类Dogclass Dog extends Animal {public void sound() {System.out.println("狗叫汪汪汪");}}// 定义子类Catclass Cat extends Animal {public void sound() {System.out.println("猫叫喵喵喵");}}// 主类public class Main {public static void main(String[] args) {Animal animal1 = new Dog(); // 使用父类引用子类对象Animal animal2 = new Cat(); // 使用父类引用子类对象animal1.sound(); // 调用子类的方法animal2.sound(); // 调用子类的方法}}```以上示例中,我们使用Animal类来声明了animal1和animal2这两个对象,并分别用Dog和Cat类的实例对其进行赋值。

大学java期末考试题及答案

大学java期末考试题及答案

大学java期末考试题及答案一、选择题(每题2分,共20分)1. Java语言的特点不包括以下哪一项?A. 跨平台B. 面向对象C. 编译型语言D. 自动内存管理答案:C2. 下列哪个是Java的关键字?A. classB. defineC. intD. array答案:A3. 在Java中,哪个修饰符表示成员变量或方法只能在同一个类内部访问?A. publicB. privateC. protectedD. static答案:B4. Java中,哪个类是所有Java类的根类?A. ObjectB. ClassC. SystemD. String答案:A5. 下列哪个不是Java集合框架中的接口?A. ListB. SetC. MapD. Array答案:D6. Java中,哪个关键字用于定义接口?A. classB. interfaceC. packageD. import答案:B7. 在Java中,哪个方法用于获取当前对象的引用?A. this()B. super()C. new()D. clone()答案:A8. 以下哪个是Java的异常处理关键字?A. tryB. catchC. finallyD. All of the above答案:D9. 在Java中,哪个关键字用于实现多态?A. abstractB. finalC. overrideD. static答案:C10. 下列哪个是Java的访问控制修饰符?A. publicB. abstractC. nativeD. synchronized答案:A二、简答题(每题5分,共10分)1. 简述Java的垃圾回收机制。

答案:Java的垃圾回收机制是指Java运行时环境自动释放不再使用的对象所占用的内存。

垃圾回收器会定期检查内存中的对象,识别那些不再被任何引用指向的对象,然后释放这些对象占用的内存。

这个过程不需要程序员手动进行,由Java虚拟机自动管理。

大学Java期末考试题库及答案

大学Java期末考试题库及答案

大学Java期末考试题库及答案第一部分:选择题1. 下列关于Java语言的说法错误的是:A. Java语言是一种解释性语言B. Java语言是一种面向对象的语言C. Java语言的跨平台特性使得它可以在不同的操作系统上运行D. Java语言最初由Sun公司开发,现在属于Oracle公司的产品答案:A2. 下列哪个不是Java中的基本数据类型?A. doubleB. booleanC. intD. string答案:D3. 下列哪种语句可以用来终止一个循环体从而强制退出循环?A. breakB. continueC. returnD. exit答案:A第二部分:编程题1. 编写一个Java程序,输出1-100中的所有偶数。

答案:public class EvenNumbers {public static void main(String[] args) {for (int i = 1; i <= 100; i++) {if (i % 2 == 0) {System.out.println(i);}}}}2. 编写一个Java程序,找到一个数组中的最大值。

答案:public class MaxValue {public static void main(String[] args) { int[] arr = {5, 2, 9, 10, 25, 1};int max = arr[0];for (int i = 1; i < arr.length; i++) {if (arr[i] > max) {max = arr[i];}}System.out.println(max);}}第三部分:简答题1. 什么是Java虚拟机?答:Java虚拟机(JVM)是一个能够执行Java字节码的虚拟机器。

它是Java平台的中心组件之一,负责将Java程序转换成真正能够在计算机上运行的指令。

2. 什么是Java中的类?答:Java中的类是一种数据结构,包括了数据和方法。

2023年JAVA语言程序设计期末考试试题及答案应考必备题库

2023年JAVA语言程序设计期末考试试题及答案应考必备题库

《JA V A语言程序设计》期末考试试题及答案4(应考必备题库)一、单选题1、下列程序段执行后的结果是( )。

String s = new String("abcdefg");for (int i=0; i<s.length(); i+=2){System.out.print(s.charAt(i));}A)aceg B) ACEG C) abcdefg D) abcd二、单选题1、下列程序段执行后的结果是( )。

String s = new String("abcdefg");for (int i=0; i<s.length(); i+=2){System.out.print(s.charAt(i));}B)A) aceg B) ACEG C) abcdefg D) ab2、有整型数组:int[] x={12,35,8,7,2};,则调用方法Arrays.sort(x)后,数组x中的元素值依次是( ).A) 2 7 8 12 35 B) 12 35 8 7 2C) 35 12 8 7 2 D) 8 7 12 35 23、下面的程序段创建了BufferedReader类的对象in,以便读取本机c盘my文献夹下的文献1.txt。

File构造函数中对的的途径和文献名的表达是( )。

File f = new File(填代码处);file =new FileReader(f);in=new BufferedReader(file);A) "./1.txt" B) "../my/1.txt" C) "c:\\my\\1.txt" D) "c:\ my\1.txt"4、应用程序的main方法中有以下语句,则输出的结果是( )。

String s1=new String("abc");String s2=new String("abc");boolean b1=s1.equals(s2);boolean b2=(s1==s2);System.out.print(b1+" "+b2);A)true false B) false true C) true true D)false false5、应用程序的main方法中有以下语句,则输出的结果是( )。

2019年秋季北邮《Java技术》期末考试复习题

2019年秋季北邮《Java技术》期末考试复习题

《Java 技术》课程 2019 年春季期末考试复习题二、考试重点(占期末考试成绩 60%)一、单项选择题1. 计算机硬件能直接执行的只能是(B)。

A. 符号语言程序B. 机器语言程序C. 汇编语言程序D. 高级语言程序2. Java 语言属于(C)。

A. 面向过程的解释型语言B. 面向过程的编译型语言C.面向对象的解释型语言D. 面向对象的编译型语言3. 根据 TIOBE 编程语言社区排行榜的统计,使用率居于前三的编程语言是(A)。

A. Java、C、C++B. Java、C#、C++C. Java、Python、RubyD. Objective-C、C++、Java4. 下述 Java 平台中,最适于开发嵌入式系统应用程序的是(C)。

A. Java SEB. Java EEC. Java MED. Java Applet5. 下面关于 Java 类文件的说法错误的是(D)。

A. Java 编译器会为源程序中的每个类单独生成一个类文件B. Java 类文件中存储的代码必须符合 JVM 规范C. Java 类文件中存储的代码是二进制形式的代码D. Java 类文件必须用 Java 语言编写得到6. 下列关于 Eclipse 说法错误的是(A)。

A. 使用 Eclipse 开发 Java 程序时,程序员编辑源程序后即可运行该程序,因此无编译程序的过程B. Eclipse 中的 Workspace 用于存储工程的路径C. 在 Windows 系统下,Eclipse 程序包解压缩后即可直接使用,无需安装D. Eclipse 是一个基于 Java 的、可扩展的、开放源代码的开发平台7. 下列关于 IDE 开发环境 Eclipse 的说法错误的是(D)。

A. Eclipse 可以通过插件(plugin)的方式扩展其功能B. Eclipse 联盟是由 IBM 公司捐资组建的C. Eclipse 使用了 SWT 图形界面技术D. Eclipse 的运行不需要有 JRE 的支持8. 关于 Eclipse 的视景说法错误的是(C)。

JAVA语言程序设计期末考试试题及答案

JAVA语言程序设计期末考试试题及答案

J A V A语言程序设计期末考试试题及答案------------------------------------------作者------------------------------------------日期JAVA语言程序设计考试试题及部分答案一、单选题:(每题 分)下列各题✌)、 )、 )、 )四个选项中,只有一个选项是正确的,请将正确选项的标记写在题干后的括号内。

.下列语句序列执行后, 的值是☎  ✆。

♓⏹♦ ❍ ⏹ ♦♒♓●♏☎ ☎❍✆  ☎  ⏹✆ ✆ ✌✆  ✆  ✆  ✆ .设 ♓、 为♓⏹♦型变量名,♋ 为♓⏹♦型数组名,以下选项中,正确的赋值语句是☎  ✆。

✌✆ ♓  ♓   ✆ ♋☯  ✆ ♓   ✆ ♋☎✆  .☺♋❖♋语言的类间的继承关系是☎  ✆。

✌✆ 多重的 ✆ 单重的 ✆ 线程的 ✆ 不能继承.设有定义 ♓⏹♦ ♓   ,则执行以下语句后,♓ 的值为☎  ✆。

♓  ♓  ✌✆  ✆  ✆  ✆ .下列选项中,用于在定义子类时声明父类名的关键字是☎  ✆。

✌)♓⏹♦♏❒♐♋♍♏ ✆ ☐♋♍♋♑♏ ✆ ♏⌧♦♏⏹♎♦ ✆ ♍●♋♦♦.若已定义 ♌⍓♦♏☯  ⌧ ❝ 其中 ≤ ≤ ,则对⌧数组元素错误的引用是☎  ✆。

✌✆ ⌧☯ ✆ ⌧☯ ✆ ⌧☯ ✆ ⌧☯.下列语句序列执行后,♍♒ 的值是☎  ✆。

♍♒♋❒ ♍♒✌♍♒♓♐☎♍♒    ♍♒ ✆ ♍♒✌✆ ✌ ✆  ✆  ✆ .下列语句序列执行后,♓ 的值是☎  ✆。

♓⏹♦ ♓ ♓♐☎ ♓   ✆ ♓ ♏●♦♏ ✌✆  ✆  ✆  ✆ .下列语句序列执行后, 的值是☎  ✆。

大二java期末考试题及答案

大二java期末考试题及答案

大二java期末考试题及答案**大二java期末考试题及答案**一、选择题(每题2分,共20分)1. 在Java中,以下哪个关键字用于声明一个类?A. classB. interfaceC. structD. enum答案:A2. Java中,哪个方法用于获取字符串的长度?A. length()B. size()C. count()D. length答案:A3. 下列哪个选项是Java中的一个合法标识符?A. 2variableB. variable2C. variable-2D. variable$2答案:B4. 在Java中,哪个关键字用于实现多态?A. abstractB. interfaceC. extendsD. implements答案:C5. 下列哪个选项是Java中的一个基本数据类型?A. StringB. IntegerC. intD. ArrayList答案:C6. Java中,哪个关键字用于声明一个方法?A. functionB. methodC. procedureD. void答案:D7. 在Java中,哪个关键字用于声明一个接口?A. classB. interfaceC. structD. enum答案:B8. 下列哪个选项是Java中的一个控制流语句?A. tryB. catchC. finallyD. all of the above答案:D9. 在Java中,哪个关键字用于声明一个枚举?A. enumB. listC. setD. map答案:A10. Java中,哪个关键字用于声明一个异常?A. errorB. exceptionC. throwableD. fault答案:B二、填空题(每题2分,共20分)1. Java中,用于声明一个类的关键字是______。

答案:class2. Java中,用于声明一个接口的关键字是______。

答案:interface3. Java的基本数据类型包括byte, short, int, long, float, double, boolean, 和______。

java期末考试题及答案大学

java期末考试题及答案大学

java期末考试题及答案大学一、选择题(每题2分,共20分)1. 在Java中,用哪个关键字可以定义一个类?A. classB. functionC. methodD. type答案:A2. 下列哪个是Java的合法标识符?A. 2classB. class#2C. _class2D. class@2答案:C3. Java中的main方法必须定义为:A. public static void main(String args[])B. private static void main(String[] args)C. public static int main(String args)D. public void main(String[] args)答案:A4. 下列哪个是Java的保留字?A. SwitchB. IntegerC. ReturnD. String答案:A5. 一个Java程序的执行是由哪个类来启动的?A. ng.ObjectB. ng.SystemC. ng.RuntimeD. ng.Thread答案:B6. 在Java中,哪个类是所有类的根类?A. ObjectB. ClassC. ThrowableD. Applets答案:A7. Java中的异常处理是通过哪两个关键字来实现的?A. try-catchB. if-elseC. switch-caseD. for-loop答案:A8. 下列哪个是Java集合框架中的接口?A. ArrayListB. HashMapC. SetD. Map答案:D9. 在Java中,哪个包包含了基本的输入输出功能?A. java.ioB. java.utilC. D. ng答案:A10. Java中的线程是继承哪个类的?A. ObjectB. ThreadC. RunnableD. Class答案:B二、填空题(每题2分,共20分)11. Java语言支持的两种数据类型是________和________。

2020年最新整理语言程序设计期末考试试题多套及答案

2020年最新整理语言程序设计期末考试试题多套及答案

2020年最新整理语言程序设计期末考试试题多套及答案《JA V A语言程序设计》期末考试试题及答案1(应考必备题库)一、单选择题1、编译Java Application 源程序文件将产生相应的字节码文件,这些字节码文件的扩展名为( B )。

A. javaB. .classC. htmlD. .exe2、设x = 1 , y = 2 , z = 3,则表达式y+=z--/++x 的值是( A )。

A. 3B. 3. 5C. 4D. 53、不允许作为类及类成员的访问控制符的是( C )。

A. publicB. privateC. staticD. protected4、为AB类的一个无形式参数无返回值的方法method书写方法头,使得使用类名AB作为前缀就可以调用它,该方法头的形式为( A )。

A. static void method( )B. public void method( )C. final void method( )D. abstract void method( )二、填空题1、开发与运行Java程序需要经过的三个主要步骤为编辑源程序、编译生成字节码和解释运行字节码。

2、在Java的基本数据类型中,char型采用Unicode编码方案,每个Unicode码占用2字节内存空间,这样,无论是中文字符还是英文字符,都是占用2字节内存空间。

3、设x = 2 ,则表达式( x + + )/3 的值是0 。

4、若x = 5,y = 10,则x < y和x >= y的逻辑值分别为true 和false。

5、抽象(abstract) 方法是一种仅有方法头,没有具体方法体和操作实现的方法,该方法必须在抽象类之中定义。

最终(final)方法是不能被当前类的子类重新定义的方法。

6、创建一个名为MyPackage 的包的语句是package MyPackage ; ,该语句应该放在程序的位置为:应该在程序第一句。

java考试题及答案期末

java考试题及答案期末

java考试题及答案期末Java编程语言是当今计算机科学领域中最重要的语言之一。

它广泛应用于各种软件开发、Web应用和移动应用程序开发中。

为了帮助大家更好地掌握Java编程知识,以下是一些期末考试题目及答案,供大家参考。

1. 以下代码片段的输出结果是什么?```javapublic class Main {public static void main(String[] args) {String str1 = "Hello";String str2 = new String("Hello");String str3 = "Hello";System.out.println(str1 == str2);System.out.println(str1 == str3);System.out.println(str1.equals(str2));}}```答案:truetrue解析:`str1`和`str3`是使用字符串字面量赋值的,它们指向的是同一个字符串常量。

因此,它们的引用地址是相等的,所以第二个输出结果是`true`。

而`str2`是使用`new`关键字创建的一个新的`String`对象,它的引用地址与`str1`和`str3`不同,所以第一个输出结果是`false`。

`str1.equals(str2)`是比较两个字符串的内容是否相等,因此输出结果为`true`。

2. 以下代码的输出结果是什么?```javapublic class Main {public static void main(String[] args) {int a = 5;int b = 2;double result = (double) a / b;System.out.println(result);}}答案:2.5解析:`a`和`b`都是整型变量,进行整数除法运算时结果会被截断为整数部分。

大专大一java期末考试题及答案

大专大一java期末考试题及答案

大专大一java期末考试题及答案一、选择题(每题2分,共20分)1. Java中,以下哪个关键字用于声明一个类?A. classB. interfaceC. structD. enum答案:A2. 下列哪个选项是Java中合法的标识符?A. 2variableB. variable2C. variable-2D. variable$2答案:B3. Java中,以下哪个选项是正确的整型字面量?A. 0x1FB. 0b1010C. 07D. 0.1答案:A4. 在Java中,以下哪个选项是正确的字符串字面量?A. "Hello, World!"B. 'Hello, World!'C. `Hello, World!`D. Hello, World!答案:A5. Java中,以下哪个选项是正确的数组声明?A. int[] myArray;B. int myArray[];C. int[] myArray = new int[5];D. int myArray = new int[5];答案:C6. Java中,以下哪个选项是正确的方法定义?A. public void myMethod() {}B. public int myMethod() {}C. public void myMethod(int x) {}D. public int myMethod() { return x; }答案:C7. 在Java中,以下哪个选项是正确的继承关系?A. class A extends B {}B. class A implements B {}C. class A implements B, C {}D. class A extends B implements C {}答案:D8. Java中,以下哪个关键字用于实现接口?A. extendsB. implementsC. extends interfaceD. interface答案:B9. 在Java中,以下哪个选项是正确的异常处理语句?A. try { } catch (Exception e) { }B. try { } finally { }C. try { } catch (Exception e) { } finally { }D. try { } catch { }答案:C10. Java中,以下哪个选项是正确的泛型声明?A. List list = new ArrayList();B. List<String> list = new ArrayList<String>();C. List list = new ArrayList<Integer>();D. List<String> list = new ArrayList<Integer>();答案:B二、填空题(每题2分,共20分)11. Java中,用于声明一个方法的关键字是________。

大二java期末试题及答案

大二java期末试题及答案

大二java期末试题及答案(本文按照试题和答案的格式来进行书写)大二Java期末试题及答案试题:题目一:Java的特点以及应用领域。

答案:Java是一种跨平台、面向对象的编程语言,具有以下几个特点:1. 简单易学:Java的语法相对简单,与C++相比,Java去除了一些复杂的特性,使得初学者更容易上手。

2. 跨平台性:Java的编译器将Java源代码编译为字节码,而不是直接编译为机器码,这样可以在不同的操作系统上运行Java程序。

只需要在特定平台上安装Java虚拟机(Java Virtual Machine, JVM),即可实现跨平台运行。

3. 面向对象:Java是一种完全面向对象的编程语言,所有的数据都是对象,所有的操作都是方法调用。

4. 垃圾回收:Java具有自动内存管理的特性,通过垃圾回收器来回收不再使用的对象所占用的内存空间,减轻了开发者的内存管理负担。

5. 安全性:Java拥有安全性机制,如对内存的访问进行控制、强制进行类型检查等,避免了一些常见的安全漏洞。

Java的应用领域包括但不限于:1. 网络编程:Java提供了丰富的网络编程类库,支持TCP/IP和UDP等协议,可以用于开发网络服务器和客户端应用。

2. 移动应用开发:通过Java开发Android应用,可以利用Java的跨平台特性,在不同的Android设备上运行。

3. 企业级应用开发:Java提供了一系列的企业级编程框架(如Spring、Hibernate等),可以用于开发大规模的企业级应用。

4. 大数据处理:Java提供了Hadoop、Spark等大数据处理框架,支持海量数据的分布式处理和分析。

题目二:什么是多态性?请用Java代码示例说明。

答案:多态性是面向对象编程中的重要概念,指的是同一类型的对象,在不同的情况下可以表现出不同的行为。

在Java中,多态性通过继承和接口实现。

Java代码示例:```java// 父类class Animal {void makeSound() {System.out.println("Animal makes sound.");}}// 子类1class Dog extends Animal {@Overridevoid makeSound() {System.out.println("Dog barks."); }}// 子类2class Cat extends Animal {@Overridevoid makeSound() {System.out.println("Cat meows."); }}public class PolymorphismExample {public static void main(String[] args) { Animal animal1 = new Dog();Animal animal2 = new Cat();animal1.makeSound(); // 输出:Dog barks.animal2.makeSound(); // 输出:Cat meows.}}```在上述示例中,Animal作为父类,Dog和Cat作为子类。

高校Java程序设计期末考试真题附答案

高校Java程序设计期末考试真题附答案

JAVA基础考试试题一、选择题(每小题 2 分,共40分)1.下列有关JAVA语言的叙述中,正确的是()A.JAVA是不区分大小写的B.源文件名与public类型的类名必须相同C.源文件名其扩展名为.jarD.源文件中public类的数目不限2.下面哪种类型不属于JAVA的基本数据类型?()A.byteB.intC.booleanD.String3.下列标识符中,()是正确的变量名?A. intB. one-hundredC. 1thingD. thing14.下列关于自动类型转换说法正确的是()A.基本数据类型和String相加结果一定是字符串类型B.char类型和int类型相加结果一定是字符C.double类型可以自动转换为intD.char+int+double+""结果一定是double5.执行下列语句后,i和n的值为()int i=10;int n= i++%5;A.10,0B. 11,0C. 10,1D. 11,16.while语句的循环体中不能包含的语句是()A.while语句B.方法定义语句C.if语句 D.switch语句7.下面声明数组的方式正确的有()A.int[] arr = new int[]{10, 20, 30}B.int[] arr = new int[3]{10, 20, 30}C.int arr[3] = {10, 20, 30}D.int[] arr = [10, 20, 30]8.下面代码输出什么?()public static void main(String[] args){char c='A';int num=10;switch(c) {case 'B':num++;case 'A':num++;case 'Y':num++;break;default:num--;}System.out.println(num);A.10B.11C.12D.139.下列方法中,不属于String的方法的是()A.toLowerCase()B.valueOf()C.charAt()D.append()10.已知如下代码,运行结果是()int i=1;int j=i++;if((i==(++j)&&(i++)==j))i+=j;System.out.println("i="+i);A.1B.2C.4D.511.定义字符串:String s1="hello";对下面程序描述正确的是if(s1=="hello")System.out.println("s1=\"hello\"");elseSystem.out.println("s1!=hello");A.输出s1!=helloB.输出s1=helloC.编译错误D.输出s1="hello"12.下面程序片段输出的是()int i=0,j=9;if(i++>--j)break;}while(i<4);System.out.println("i="+i+" and j="+j);A.i=4 and j=4B.i=5 and j=5C.i=5 and j=4D.i=4 and j=513.下列构造方法的调用方式中,正确的是()A.按照一般方法调用B.由用户直接调用C.只能通过new自动调用D.被系统调用14.给定如下JAVA程序,编译运行时,将在()语句出现错误。

完整word版北邮《Java技术》期末复习题含答案

完整word版北邮《Java技术》期末复习题含答案

<<Java技术>>综合练习题填空题Java不仅仅是一种编程环境,它实际上是一个完整的计算平台,包括完整的程序开发环境和运行环境。

2. 完整的Java体系结构包括四个组件,分别是Java 编程语言、Java类文件格式、Java应用程序编程接口和Java虚拟机。

Java运行时环境是由Java虚拟机和核心类组合形成的。

4. 在Java类文件中存储的二进制代码称为字节码,它们是JVM的指令。

当Java虚拟机是在主机操作系统上由软件实现时,它实际上是用本地〔如C/C++等〕语言编写的程序。

Java虚拟机主要包括两个模块,一个是类装载器,另一个是执行引擎。

在面向对象系统中,对象是程序的根本组成实体。

对象是程序的根本组成实体,类是创立对象的模板。

Java源程序中的类可以分为两种,分别是系统类和用户自己定义类。

编译程序的时候会自动导入到程序中的系统包是。

把根本数据类型包装成类包装成类的好处是可以提供根本数据类型的信息,还可以使用类的方法对数据进行操作。

在Java中,int类型的包装类是Integer,char类型的包装类是Character。

Integer类的parseInt()方法的功能是把一个字符串转换为一个整型数据。

1 4.Java把数据输出到控制台是使用完成的。

15.Scanner类是在包中定义的。

1 6.创立一个连接到标准输入流对象的17.Scanner对象的语句是ScannermyScanner=newScanner(System.in);。

设myS是一个Scanner类的实例,那么语句“intx=myS.nextInt();〞的作用是读取一个整数,然后把这个整数赋给变量x。

Java提供的专门用于格式化输出数据的方法是System.out.printf()。

Java提供的用于处理日期和时间信息的系统类是。

字符串常量是用双引号括起来的字符序列。

Java用于处理处理字符串的类有两个,分别是String类和StringBuffer类。

北京联合大学师范学院java期末考试1选择

北京联合大学师范学院java期末考试1选择

Object-Oriented Programming encapsulates:A. Data and methods.B. Information hiding.C. Classes.D. AdjectivesIf class A extends B, then:A. Class A is the base class.B. Class A is the superclass.C. Class A inherits from class B.D. Class B is the derived class.What will happen if you try to compile and run the following codepublic class MyClass{public static v oid main(String arguments[]){amethod(arguments);}public void amethod(String[] arguments){System.out.println(arguments);System.out.println(arguments[1]);}}A) error Can't make static reference to void amethod.B) error method main not correctC) error array must include parameterD) amethod must be declared with StringAn instance variable has which of the following scopes?A. Block scope.B. Method scope.C. Class scope.D. None of the above.Which of the following statements about arrays are true? (1). Arrays are a group of contiguous memory locations, where each location is an element.(2). Elements are located by subscript or index.(3). The length of array c is determined by the expressionc.length();(4). The seventh element of array c is specified by c[7].A. (1), (3), (4)B. (1), (2)C. (3), (4)D. (1), (2), (3), (4).A package is:A. A directory structure used to organize classes and interfaces.B. A mechanism for software reuse.C. A group of related classes and interfaces.D. All of the above.Constructors:A. Have the same name as the class.B. May not specify a return type.C. Are called automatically when an object is instantiated.D. All of the above.An instance variable is hidden in the scope of a method whenA. The instance variable has the same name as the method.B. The instance variable has the same name as a local variable in the method.C. The instance variable has the same name as the class.D. The instance variable has the same name as the file..Read the following program:public class Test{public static void main(String[] args){String foo = args [1];System.out.println(args [1]+80);}}And command line invocation:Java Test 1 8 9What is the result?A. 880B. The program throws an exception.C. 88D. The code does not compile.Which of the following will be used to create an instances of a class if the programmer does not define a constructor?A. A default constructor.B. An overloaded constructor.C. The Object class constructor with the name of the desired class passed in as an argument.D. If no constructor is written, then one is not needed.When overriding the method paintComponent( Graphics g ) A. The statement super.paintComponent(g) must be the last statement in the overriding method.B. The statement super.paintComponent(g) must be the first statement in the overriding method.C. The statement super.paintComponent(g) must occur after any customized drawing statements.D. The statement super.paintComponent(g) must not be used.Advantages of using interfaces include which of the following: a. Flexibility in implement ation and in accommodating later functionality.b. Providing standard values for many different classes to use.c. Increasing opportunities to use polymorphism多态.d. Creating a bank of methods for which the code is hidden so that the classes whic h implement the interfaces don’t have to define them.A.All of the above.B.None of the above.C.a, c and d.D.a, b and c.Which of the following is not a valid Java identifier标识符?aa.my Valueb.$_AAA1c.widthd.m_xWhich of the following cannot cause a syntax error to be reported by the Javacompiler? da.Mismatched {}b.Missing */ in a commentc.Missing ;d.Extra blank lines.Which command compiles the Java source code file Welcome.java? ba.cd Welcome.javab.javac Welcome.javac.java Welcome.javapile Welcome.javaWhich command executes the Java class file Welcome.class?ca.javac Welcome.classb.java Welcome.classc.java Welcomed.run Welcome.classWhich of the following statement displays Hello World? ba.System.out.printf( “%2s”, “Hello ” “World” );b.System.out.p rintf( “%s %s”, “Hello”, “World” );c.System.out.printf( “%s%s”, “Hello, World” );d.System.out.printf( “s% s%”, “Hello”, “World” );A(n) ________ enables a program to read data from the user.ca.printf.b.import declaration.c.Scanner.d.main.What is the value of result after the following Java statements execute? aint a, b, c, d, result;a = 4;b = 12;c = 37;d = 51;result = d % a * c + a % b + a;a.119b.51c.127d.59Which of the following statements about the break statement is false? ca.The break statement is used to exit a repetition structureearly and continue execution after the loop.b.A break statement can only break out of an immediatelyenclosing while, for, do…while or switch statement..c.The break statement, when executed in a while, for ordo…w hile, skips the remaining statements in the loopbody and proceeds with the next iteration of the loop.mon uses of the break statement are to escape earlyfrom a loop or to skip the remainder of a switch.Method headers contain all of the following except: ba. Access modifier.b. Left brace.c. Name of method.d. Return type.Every Java application is composed of at least one: ca.public methodb.data memberc.public class declarationd.imported classCalling a method of an object requires which item? aa. The dot separator.b. Open and close braces.c. The new keyword.d.None of the above.Which of the following statements about the continue statement is true? da.The continue statement is used to exit a repetition structureearly and continue execution after the loop.b.The continue statement is used to continue after a switchstatement.c.The continue statement does not alter the flow of control.d.A continue statement proceeds with the next iteration of theimmediately enclosing while, for, do…while statement. What is the default value of a reference? ca. 0.b. “”.c. null.d. default.What is output by the following Java code segment? d int temp;temp = 180;if ( temp > 90 ){System.out.println( "This porridge is too hot." );// cool downtemp = temp – ( temp > 150 ? 100 : 20 );} // end ifelse{if ( temp < 70 ){System.out.println("This porridge is too cold.");// warm uptemp = temp + (temp < 50 ? 30 : 20);} // end if} // end elseif ( temp == 80 )System.out.println( "This porridge is just right!" );a.This porridge is too hot.b.This porridge is too cold.This porridge is just right!c.This porridge is just right!d.None of the above.Suppose variable gender is MALE and age equals 60, how is the expression( gender == FEMALE ) && ( age >= 65 )evaluated? aa.The condition ( gender == FEMALE ) is evaluated firstand the evaluation stops immediately.b.The condition ( age >= 65 ) is evaluated first and theevaluation stops immediately.c.Both conditions are evaluated, from left to right.d.Both conditions are evaluated, from right to left.How many times is the body of the loop below executed? d int counter;counter = 1;while ( counter > 20 ){// body of loopcounter = counter + 1;} // end whilea.19.b.20.c.21.d.0.Which of the following terms is NOT used to refer to asentinel value that breaks out of a while loop? ba.signal value.b.break out value.c.dummy value.d.flag value.Which statement is false? ca.To ensure that the operands are of the same type, Javaperforms implicit conversion on selected operands.b.Cast operators are unary operators.c.Cast operators associate from right to left and are one levellower than the multiplicative(乘法的)operators.d.Case operators are formed by placing parentheses aroundthe name of a type.Local variables must be ________. ba.initialized when they are declared.b.initialized before their values are used in an expression.c.declared and initialized in two steps.d.declared at the top of the method.Which of the following code segments does not increment val by 3: ca.val += 3:b.val = val+1;val = val+1;val = val+1;c.c = 3;val = val + (c == 3 ? 2 : 3);d. All of the above increment val by 3.What does the expression x %= 10 do? ba.Adds 10 to the value of x, and stores the result in x.b.Divides x by 10 and stores the remainder in x.c.Divides x by 10 and stores the integer result in x.d.None of the above.What is the result value of c at the end of the following code segment? aint c = 8;c++;++c;c %= 5;a.0.b.1.c.3.d.None of the above.Keyword ________ represents the inheritance relationship. aa.extends.b.inherits.c.super.d.sub.Which statement prints the floating-point value 123.456 right justified with a field width of 10? da.System.out.printf( “%d10.3”, 123.456 );b.System.out.printf( “%10.3d”, 123.456 );c.System.out.printf( “%f10.3”, 123.456 );d.System.out.printf( “%10.3f”, 123.456 );For the code segment below,switch( q ){case 1:System.out.println( "apple" );break;case 2:System.out.println( "orange" );break;case 3:System.out.println( "banana" );break;case 4:System.out.println( "pear" );case 5:System.out.println( "grapes" );default:System.out.println( "kiwi" );} // end switchWhich of the following values for q will result in kiwi being output? ba.2.b.4 and anything greater than 4.c.1.d.3.。

北京联合大学师范学院java期末考试3填空和程序

北京联合大学师范学院java期末考试3填空和程序

1.Input a integer and assign the result to int variable value. AssumeScanner variable input can be used to read a value from the keyboard. Value+input.nextInt();2.Methods of a class are normally made ______ and instancevariables of a class are normally made private. public3.A ______ method is used to assign values to private instancevariables of a class. set4.Create a Scanner that reads values from the standard input.Scanner input=new Scanner(System.in)5.Java applications begin execution at method ______ .main6.All programs can be written in terms of three types of controlstructures : sequence, selection and _________. repetition 7.A (n) ________ is not required if you always refer to a class withits fully qualified class name. import declaration8.A java program file must end with the _______ file extension.java9.A house is to a blueprint as a(n) ______is to a class. object10.Every class declaration contains keyword _______ followedimmediately by the class’s name.class11.Keyword_______ creates an object of the class specified to theright of the keyword. new12.By default, classes that are compiled in the same directory areconsidered to be in the same packageknown as the _______.Default package13.When each object of a class maintains its own copy of anattribute, the field that represents the attribute is also known as a (n) _______. Instance variable14.Return type ______ indicates that a method will perform a taskbut will not return any information when it completes its task.void15.Class String is in package. ng16.Types in Java are divided into two categories primitive types and___ types. reference17.Instance variables of types char , byte , short , int , long , floatand double are all given the value ________ by default.0(zero)18.Calculate the value of 2.5 raised to the power of 3, using the powmethod: ________. Double result =Math.pow(2.5,3)21. In a double-subscripted array, the first subscript identifies the row of an element and the second subscript identifies the ____ of an element. ( column).22. In the Java coordinate system, y values increase _____. (from top to bottom)23. The _____ class is used to create a group of JradioButtons and it inherits from class ______. (ButtonGroup,Object)24. The new operator dynamically allocates memory for an object ofa specified type and returns a _____ to that type.(reference)25.The keyword ____ specifies that an object or variable is not modifiable after it is initialized. (final)26. An object of a sub class ______(can/can not) be treated as an object of its corresponding super class. (can)27. A method declared static cannot access ____ class members. (nonstatic)33.Members of a class specified as ______ are accessible only to methods of the class. (private)28. A(or An) ______ is a collection of abstract methods that can be implemented to simulate multiple inheritance.( interface)29. A “has a” relationship between classes represents _____ and an “is a” relationship between classes rep resents inheritance. (composition,)30. A subclass may call any nonprivate superclass method by prepending ____ to the method call. (super)31.The Graphics is a/an ________ class and inherits directly from class Object. (abstract)32. A Jpanel object ___ (is/is not)capable of receiving mouse events.( is)33.Method ____ is called when the mouse is moved and an event listener is registered to handle the event.(mouseMoved)35. Class members are accessed via the ______ operator in conjunction with a reference to an object of the class.( dot(.))36. A superclass typically represents a _____(larger/smaller) number of objects than its subclass represents. (larger)37. A subclass typically encapsulates ____ (less/more) functionality than does its superclass. (more)程序填空1._______ java.until.Scanner;Public class Addition{Public ______ void main(String args[]){//create Scanner to obtion input from command windowScanner input= ________ ;Int number1;//first number to addInt number2;//sceond number to addInt sum;//sum of number 1 and number2System.out.print(“Enter first integer:”);//promptNumber1=input.nextint();//read first number from userSystem.out.print(“Enter first integer:”);//promptNumber2= __________ ;//read second number from user__________ ;//add numbersSystem.out.printf(“Sum is %d\n”,sum);//display sum }//end method main}//end class Addition1import2static3new Scanner(system.in)4input.nextInt()5sum=number1+number22.下面的方法的功能是生成1~36之间的K个(方法参数指定)随即整数,保存到ArrayList对象中并返回,请将程序补充完整。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

Object-Oriented Programming encapsulates:A. Data and methods.B. Information hiding.C. Classes.D. AdjectivesIf class A extends B, then:A. Class A is the base class.B. Class A is the superclass.C. Class A inherits from class B.D. Class B is the derived class.What will happen if you try to compile and run the following codepublic class MyClass{public static v oid main(String arguments[]){amethod(arguments);}public void amethod(String[] arguments){System.out.println(arguments);System.out.println(arguments[1]);}}A) error Can't make static reference to void amethod.B) error method main not correctC) error array must include parameterD) amethod must be declared with StringAn instance variable has which of the following scopes?A. Block scope.B. Method scope.C. Class scope.D. None of the above.Which of the following statements about arrays are true? (1). Arrays are a group of contiguous memory locations, where each location is an element.(2). Elements are located by subscript or index.(3). The length of array c is determined by the expressionc.length();(4). The seventh element of array c is specified by c[7].A. (1), (3), (4)B. (1), (2)C. (3), (4)D. (1), (2), (3), (4).A package is:A. A directory structure used to organize classes and interfaces.B. A mechanism for software reuse.C. A group of related classes and interfaces.D. All of the above.Constructors:A. Have the same name as the class.B. May not specify a return type.C. Are called automatically when an object is instantiated.D. All of the above.An instance variable is hidden in the scope of a method whenA. The instance variable has the same name as the method.B. The instance variable has the same name as a local variable in the method.C. The instance variable has the same name as the class.D. The instance variable has the same name as the file..Read the following program:public class Test{public static void main(String[] args){String foo = args [1];System.out.println(args [1]+80);}}And command line invocation:Java Test 1 8 9What is the result?A. 880B. The program throws an exception.C. 88D. The code does not compile.Which of the following will be used to create an instances of a class if the programmer does not define a constructor?A. A default constructor.B. An overloaded constructor.C. The Object class constructor with the name of the desired class passed in as an argument.D. If no constructor is written, then one is not needed.When overriding the method paintComponent( Graphics g ) A. The statement super.paintComponent(g) must be the last statement in the overriding method.B. The statement super.paintComponent(g) must be the first statement in the overriding method.C. The statement super.paintComponent(g) must occur after any customized drawing statements.D. The statement super.paintComponent(g) must not be used.Advantages of using interfaces include which of the following: a. Flexibility in implement ation and in accommodating later functionality.b. Providing standard values for many different classes to use.c. Increasing opportunities to use polymorphism多态.d. Creating a bank of methods for which the code is hidden so that the classes whic h implement the interfaces don’t have to define them.A.All of the above.B.None of the above.C.a, c and d.D.a, b and c.Which of the following is not a valid Java identifier标识符?aa.my Valueb.$_AAA1c.widthd.m_xWhich of the following cannot cause a syntax error to be reported by the Javacompiler? da.Mismatched {}b.Missing */ in a commentc.Missing ;d.Extra blank lines.Which command compiles the Java source code file Welcome.java? ba.cd Welcome.javab.javac Welcome.javac.java Welcome.javapile Welcome.javaWhich command executes the Java class file Welcome.class?ca.javac Welcome.classb.java Welcome.classc.java Welcomed.run Welcome.classWhich of the following statement displays Hello World? ba.System.out.printf( “%2s”, “Hello ” “World” );b.System.out.p rintf( “%s %s”, “Hello”, “World” );c.System.out.printf( “%s%s”, “Hello, World” );d.System.out.printf( “s% s%”, “Hello”, “World” );A(n) ________ enables a program to read data from the user.ca.printf.b.import declaration.c.Scanner.d.main.What is the value of result after the following Java statements execute? aint a, b, c, d, result;a = 4;b = 12;c = 37;d = 51;result = d % a * c + a % b + a;a.119b.51c.127d.59Which of the following statements about the break statement is false? ca.The break statement is used to exit a repetition structureearly and continue execution after the loop.b.A break statement can only break out of an immediatelyenclosing while, for, do…while or switch statement..c.The break statement, when executed in a while, for ordo…w hile, skips the remaining statements in the loopbody and proceeds with the next iteration of the loop.mon uses of the break statement are to escape earlyfrom a loop or to skip the remainder of a switch.Method headers contain all of the following except: ba. Access modifier.b. Left brace.c. Name of method.d. Return type.Every Java application is composed of at least one: ca.public methodb.data memberc.public class declarationd.imported classCalling a method of an object requires which item? aa. The dot separator.b. Open and close braces.c. The new keyword.d.None of the above.Which of the following statements about the continue statement is true? da.The continue statement is used to exit a repetition structureearly and continue execution after the loop.b.The continue statement is used to continue after a switchstatement.c.The continue statement does not alter the flow of control.d.A continue statement proceeds with the next iteration of theimmediately enclosing while, for, do…while statement. What is the default value of a reference? ca. 0.b. “”.c. null.d. default.What is output by the following Java code segment? d int temp;temp = 180;if ( temp > 90 ){System.out.println( "This porridge is too hot." );// cool downtemp = temp – ( temp > 150 ? 100 : 20 );} // end ifelse{if ( temp < 70 ){System.out.println("This porridge is too cold.");// warm uptemp = temp + (temp < 50 ? 30 : 20);} // end if} // end elseif ( temp == 80 )System.out.println( "This porridge is just right!" );a.This porridge is too hot.b.This porridge is too cold.This porridge is just right!c.This porridge is just right!d.None of the above.Suppose variable gender is MALE and age equals 60, how is the expression( gender == FEMALE ) && ( age >= 65 )evaluated? aa.The condition ( gender == FEMALE ) is evaluated firstand the evaluation stops immediately.b.The condition ( age >= 65 ) is evaluated first and theevaluation stops immediately.c.Both conditions are evaluated, from left to right.d.Both conditions are evaluated, from right to left.How many times is the body of the loop below executed? d int counter;counter = 1;while ( counter > 20 ){// body of loopcounter = counter + 1;} // end whilea.19.b.20.c.21.d.0.Which of the following terms is NOT used to refer to asentinel value that breaks out of a while loop? ba.signal value.b.break out value.c.dummy value.d.flag value.Which statement is false? ca.To ensure that the operands are of the same type, Javaperforms implicit conversion on selected operands.b.Cast operators are unary operators.c.Cast operators associate from right to left and are one levellower than the multiplicative(乘法的)operators.d.Case operators are formed by placing parentheses aroundthe name of a type.Local variables must be ________. ba.initialized when they are declared.b.initialized before their values are used in an expression.c.declared and initialized in two steps.d.declared at the top of the method.Which of the following code segments does not increment val by 3: ca.val += 3:b.val = val+1;val = val+1;val = val+1;c.c = 3;val = val + (c == 3 ? 2 : 3);d. All of the above increment val by 3.What does the expression x %= 10 do? ba.Adds 10 to the value of x, and stores the result in x.b.Divides x by 10 and stores the remainder in x.c.Divides x by 10 and stores the integer result in x.d.None of the above.What is the result value of c at the end of the following code segment? aint c = 8;c++;++c;c %= 5;a.0.b.1.c.3.d.None of the above.Keyword ________ represents the inheritance relationship. aa.extends.b.inherits.c.super.d.sub.Which statement prints the floating-point value 123.456 right justified with a field width of 10? da.System.out.printf( “%d10.3”, 123.456 );b.System.out.printf( “%10.3d”, 123.456 );c.System.out.printf( “%f10.3”, 123.456 );d.System.out.printf( “%10.3f”, 123.456 );For the code segment below,switch( q ){case 1:System.out.println( "apple" );break;case 2:System.out.println( "orange" );break;case 3:System.out.println( "banana" );break;case 4:System.out.println( "pear" );case 5:System.out.println( "grapes" );default:System.out.println( "kiwi" );} // end switchWhich of the following values for q will result in kiwi being output? ba.2.b.4 and anything greater than 4.c.1.d.3.。

相关文档
最新文档