77范文网 - 专业文章范例文档资料分享平台

《JAVA语言程序设计》期末考试试题及答案2(题库超级大全 - 应考(3)

来源:网络收集 时间:2020-06-08 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

21. 给出下面的不完整的方法 1

2 { success = connect(); 3 if (success==-1) {

4 throw new TimedOutException(); 5 } 6 }

已知TimedOutException 不是一个RuntimeException。下面的哪些声明可以被加入第一行完成此方法的声明 [BC]

A. public void method()

B. public void method() throws Exception

C. public void method() throws TimedOutException D. public void method() throw TimedOutException E. public throw TimedOutException void method()

22. 给出下面的代码 class Person {

String name,department; public void printValue(){

System.out.println(\

System.out.println(\ } }

public class Teacher extends Person { int salary;

public void printValue(){

// 完成父类代码中printValue()相同的工作 System.out.println(\ } }

下面的哪些表达式可以加入printValue()方法的注释部分? [D] A. printValue();

B. this.printValue(); C. person.printValue(); D. super.printValue();

23. 下面的哪些赋值语句是错的? [A] A. float f = 11.1; B. double d = 5.3E12; C. double d = 3.14159; D. double d = 3.14D;

24. 给出下面的不完整的类代码 class Person {

String name, department; int age;

public Person(String n){ name = n; }

public Person(String n, int a){ name = n; age = a; } public Person(String n, String d, int a) { // 完成Person(String n, int a)的逻辑 department = d; } }

下面的哪些表达式可以加到构造方法中的注释处? [C] A. Person(n,a);

B. this(Person(n,a)); //构造函数的名字不能当方法名调用; C. this(n,a);

D. this(name,age); //构造方法的参数也不能直接传实例变量名 25. 下面关于变量及其范围的陈述哪些是对的? [ACD] A. 实例变量是类的成员变量。

B. 实例变量用关键字static声明。

C. 在方法中定义的局部变量在该方法被执行时创建 D. 局部变量在使用前必须被初始化。 26. 给出下面的代码 public void test() { try {

oneMethod();

System.out.println(\

} catch (ArrayIndexOutOfBoundsException e) { System.out.println(\ } catch(Exception e) {

System.out.println(\ } finally {

System.out.println(\ } }

在oneMethod()方法运行正常的情况下将显示什么? [AD] A. condition 1 B. condition 2 C. condition 3 D. finally

27. 给出下面的代码 public class Test {

void printValue(int m){ do {

System.out.println(\ }while( --m > 10 ); }

public static void main(String arg[]) { int i=10;

Test t= new Test(); t.printValue(i); } }

输出将是什么? [C] A. 8 B. 9 C. 10 D. 11

28. 下面的有关声明的哪些叙述是对的? [BC]

A. 对原始数据类型例如boolean,byte的变量的声明不会为该变量分配内存空间。 B. 对原始数据类型例如boolean,byte的变量的声明将为之分配内存空间。 C. 非原始数据类型例如String,Vector的变量的声明不会为该对象分配内存。 D. 非原始数据类型例如String,Vector的变量的声明会为该对象分配内存。 //该对象指的是堆空间的对象;指向该对象的引用只能叫变量;

29. 类的设计要求它的某个成员变量不能被外部类直接访问。应该使用下面的哪些修饰符获得需要的访问控制? [D]

A. public B. 不加修饰符 C. protected

D. private //面向对象编程P196页的表格,private一行有错误 30. 给出下面的代码片断 1 String str = null;

2 if ((str != null) && (str.length() > 10)) { 3 System.out.println(\ 4 }

5 else if ((str != null) & (str.length() < 5)) {//空指针异常 6 System.out.println(\ 7 }

8 else { System.out.println(\

哪些行将导致错误? [C] A. 第1行 B. 第2行 C. 第5行 D. 第8行

31. 下面有关java代码安全性的叙述哪些是对的? [BCD] A. 字节码校验器加载查询执行需要的所有类。 B. 运行时解释器执行代码。

C. 在运行时,字节码被加载,验证然后在解释器里面运行。

D. 类加载器通过分离本机文件系统的类和从网络导入的类增加安全性。 32. 给出下面的代码 public class Person{

int arr[] = new int[10];//非静态属性 public static void main(String a[]) {

System.out.println(arr[1]);//静态方法不能访问非静态属性 } }

哪些叙述是对的? [A] A. 编译时出错。

B. 编译时正确而运行时出错。 C. 输出0。 D. 输出null。

33. 给出下面的代码

public class Parent {

public int addValue( int a, int b) { int s; s = a+b; return s; } }

class Child extends Parent { }

哪些方法可以加入类Child中? [BC] //方法的覆盖 A. int addValue( int a, int b ){// do something...} B. public void addValue (){// do something...}

C. public int addValue( int a ){// do something...}

D. public int addValue( int a, int b )throws Exception {//do something...}

34. 公有成员变量MAX_LENGTH是一个int型值,变量的值保持常数值100,定义这个变量的代码为? [CD] A. public int MAX_LENGTH=100; B. final int MAX_LENGTH=100;

C. final public int MAX_LENGTH=100; //修饰符的顺序可以交换 D. public final int MAX_LENGTH=100;

35. 下面的哪些java源文件代码片断是对的? [ACD] A. package testpackage;

public class Test{//do something...} B. import java.io.*; package testpackage;

public class Test{// do something...} C. import java.io.*;

class Person{// do something...}

public class Test{// do something...} D. import java.io.*; import java.awt.*;

public class Test{// do something..} 36. 给出下面的类

public class Sample{ long length;

public Sample(long l){ length = l; } public static void main(String arg[]){

Sample s1, s2, s3; s1 = new Sample(21L); s2 = new Sample(21L); s3 = s2;

long m = 21L; } }

哪个表达式返回true? [B] A. s1 == s2; B. s2 == s3; C. m == s1;

D. s1.equals(m);

37. 给出下面有关java.awt.List的表达式

List l = new List(6,true);//第二个参数是false的话只能选一个 其中哪些叙述是正确的? [AC]

A. 在没有其它的约束的条件下该列表将有6行可见。 B. 一行的最大字符数是6 C. 列表将允许用户多选 D. 列表只能有一项被选中 38. 给出下面的代码 class Parent {

String one, two;

public Parent(String a, String b){ one = a; two = b; }

public void print(){ System.out.println(one); } }

public class Child extends Parent { public Child(String a, String b){ super(a,b); }

public void print(){

System.out.println(one + \ }

public static void main(String args[]){ Parent p = new Parent(\ Parent t = new Child(\ p.print(); t.print(); } }

下面的哪些情况或输出的结果正确? [E] A. 编译时出错 B. south east

C. south to north east to west D. south to north east E. south

east to west

39. 类Teacher和Student都是类Person的子类 Person p; Teacher t; Student s;

若p,t和s都是非空值

if(t instanceof Person) { s = (Student)t; }

这个语句导致的结果是什么? [C] // 默认new时声明的都是本类;

A. 将构造一个Student对象 B. 表达式合法 C. 编译时非法

D. 编译时合法而在运行时可能非法 40. 给出下面的代码 String s= \String t = \

char c[] = {'h','e','l','l','o'}; 下列选项里,哪些返回true? [ACD] A. s.equals(t); B. t.equals(c); C. s==t;

D. t.equals(new String(\E. t==c;

一、单选题(本大题15小题,每小题2分,共30分) 1.下列语句执行后,变量a、c的值分别是( )。 int x=182;

int a,c;

c=x/100; a=x;

A) 1,2 B) 2,1 C) 1.82, 2 D) 100,82 【答案】B 2.下面哪个表达式可用得到x和y的最大值( )?

A) x>y?y:x B) xy?(x+y):(x-y) D) x==y?y:x; 【答案】B 3.以下是应用程序中定义的静态方法printBinary,若在其main方法中有方法调用语句printBinary(2),则输 出的结果是 ( )。

static void printBinary(int i) {

System.out.print(i + \的2进制数表示为:\\t\ for(int j = 31; j >=0; j--) if(((1 << j) & i) != 0) System.out.print(\ else

System.out.print(\ System.out.println();//换行 }

A) 00000000000000000000000000000001 B) 00000000000000000000000000000010

C) 00000000000000000000000000001111 D) 00000000000000000000000000000000 【答案】B 4. 应用程序的main方法中有以下语句,则输出的结果是 ( )。 String s1=\

double x=Double.parseDouble(s1); int y=Integer.parseInt(s2); System.out.println(x+y);

A) 12.5 B) 120.5 C) 12 D) ?12.5? 【答案】A 5. 应用程序的main方法中有以下语句,则输出的结果是 ( )。 double x=1234.1234567;

DecimalFormat form1 = new DecimalFormat(\ System.out.println(\A) PI=1234.1 B) PI=1234

C) PI=1234.1235 D) PI=1234.0 【答案】A 6.下列程序段执行后的结果是( )。 String s=new String(\for(int i=0;i

A) aceg B) ACEG C) abcdefg D) abcd 【答案】A 7. 应用程序的main方法中有以下语句,则输出的结果是 ( )。 int[] x={122,33,55,678,-987}; int max=x[0];

for(int i=1;imax)

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说教育文库《JAVA语言程序设计》期末考试试题及答案2(题库超级大全 - 应考(3)在线全文阅读。

《JAVA语言程序设计》期末考试试题及答案2(题库超级大全 - 应考(3).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/jiaoyu/1100857.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: