大学java期末试题java选择题.docx
《大学java期末试题java选择题.docx》由会员分享,可在线阅读,更多相关《大学java期末试题java选择题.docx(50页珍藏版)》请在冰豆网上搜索。
大学java期末试题java选择题
20XX年复习资料
大
学
复
习
资
料
专业:
班级:
科目老师:
日期:
Java 程序设计习题
单项选择题(80)
1. 接口中的成员变量被隐含地声明为
(A)public static final
(B)public final
(C)public static
(D)public abstract
2. 处理按钮点击事件的类需要实现哪个接口
(A)FocusListener
(B)ActionListener
(C)WindowListener
(D)ItemListener
3. 已知:
class A {
public final void m() {
System.out.println("A.m");
}
}
public class B extends A {
public void m() {
System.out.println("B.m");
super.m();
}
public static void main(String [] args) {
new B().m();
}
}
那么结果为?
(A)A.m
(B)B.m
(C)B.m
A.m
(D)编译错误
4. 抛出异常,使用关键字
(A)try
(B)throw
(C)finally
(D)catch
5. 已知:
class Base {
public Base(String s) {
System.out.print("B");
}
}
public class Derived extends Base {
public Derived (String s) {
System.out.print("D");
}
public static void main(String [] args) {
new Derived ("C");
}
}
那么结果为?
(A)BD
(B)DB
(C)C
(D)编译错误
6. Java 中char 类型的数据长度为
(A)8 位
(B)20XXXX 位
(C)32 位
(D)64 位
7. Java 编译输出文件的后缀是
(A).exe
(B).java
(C).class
(D).obj
8. 已知:
class C {
public static void main(String[] args) {
boolean a = true;
boolean b = false;
boolean c = true;
if((a & b) | (b & c) & c)
System.out.print(“A”);
If((a = false) | (a & c) ) | (a | b))
System.out.print(“B”);
}
}
(A)A
(B)B
(C)AB
(D)编译错误
9. 下面哪个表达式是错误的
(A)int i = 20XXXX0;
(B)float f = 20XXXX0.0;
(C)Object o = “Hello world”;
(D)char c = ‘\u20XXXX34’;
20XXXX. 引用类型的数据字段的缺省值为
(A)0.0
(B)0
(C)null
(D)false
20XXXX. 下面哪个表达式可以获取字符串s 的最后一个字符
(A)s.length()
(B)s[s.length() - 1]
(C)s.charAt(s.length() - 1)
(D)charAt(s, length(s))
20XXXX. 数据字段的作用域是
(A)所在的语句块
(B)所在的类
(C)所在的方法
(D)所在的构造函数
20XXXX. 如果类中的成员只能被子类或同一包中的类访问,那么声明该成员时应使用下面哪个修
饰符
(A)private
(B)package
(C)protected
(D)public
20XXXX. import 语句的作用是
(A)导入包中成员
(B)创建包
(C)既可导入包成员,也可创建包
(D)访问控制
20XXXX. 已知:
class C {
public static void main(String[] args) {
int a = 1;
int b = 2;
System.out.print(“7” + 5 + 4);
System.out.print(m() + a + 3);
System.out.println(a + b + m());
}
public static String m() {
return “6”;
}
}
(A) 720XXXX20XXXX20XXXX6
(B) 720XXXX20XXXX336
(C) 754620XXXX36
(D) 754620XXXX20XXXX6
20XXXX. 接口中的成员方法被隐含地声明为
(A)public static final
(B)protected abstact
(C)private
(D)public abstract
20XXXX. 关于包的描述错误的是
(A)包可以将相关的类和接口组织在一起,便于识别和管理
(B)包中的类可以访问同一包的其它类的私有成员
(C)不同包中的相同命名,不会产生冲突
(D)用public 修饰的顶级类和接口对包外代码可见
20XXXX. 下面代码的输出是
class C {
public static void main(String[] args) {
int x = 1;
System.out.print((x > 1) & (x++ > 1));
System.out.print(“ ”);
System.out.print((x > 1) && (x++ > 1));
}
}
(A)false true
(B)true false
(C)false false
(D)true true
20XXXX. float[] f = new float[20XXXX],则f[0]的值为
(A)0.0
(B)0.0f
(C)null
(D)false
20XX. 下面哪个类不能直接读取磁盘文件
(A)
(B)RandomAccessFile
(C)FilterReader
(D)
21. 如果类中的成员只能被同一包中的类访问,那么声明该成员时应使用下面哪个修饰符
(A)protected
(B)package
(C)public
(D)不使用访问修饰符
22. 表达式new StringTokenizer(“Welcome to java”).countTokens()的值是
(A)1
(B)3
(C)20XXXX
(D)20XXXX
23. JPanel 的缺省布局管理器是
(A)BorderLayout
(B)FlowLayout
(C)GridLayout
(D)SpringLayout
24. JFrame 的缺省布局管理器是
(A)BorderLayout
(B)FlowLayout
(C)GridLayout
(D)BoxLayout
25. 已知:
public class C {
public int m(int x) {
int r = 1;
r += x;
if ((x > 5) && (x < 20XXXX)) {
r += 2 * x;
} else (x <= 4) {
r += 3 * x;
} else {
r += 4 * x;
}
r += 5 * x;
return r;
}
public static void main(String [] args) {
C o = new C();
System.out.println("m(20XXXX) = " + o.m(20XXXX));
}
}
(A)m(20XXXX) = 45
(B)m(20XXXX) = 56
(C)m(20XXXX) = 89
(D)m(20XXXX) = 20XXXX1
26. 已知:
目录结构
dira
|---A.class
|---dirb
|---B.class
和源代码
import dira.*;
class C {
A a;
B b;
}
那么要使源代码通过编译,需要在源代码中添加
(A)package dira;
(B)package dirb;
(C)package dira.dirb;
(D)package dirb.dira;
27. 如果java.awt.Container c 的布局为BorderLayout,则c.add(new Jbutton())的默认
位置参数是
(A)BorderLayout.EAST
(B)BorderLayout.WEST
(C)BorderLayout.CENTER
(D)编译错误
28. 已知:
class C {
public static void main(String[] args) {
String s = “welcome to java”;
System.out.println(s.substring(20XXXX));
}
}
的输出为
(A)java
(B)welcome to
(C)ome to java
(D)welcome to java
29. 已知:
class C {
int i = 1;
int j = 2;
public void swap() {
int temp = i;
i = j;
j = temp;
}
public static void main(String[] args) {
C c = new C();
c.swap();
System.out.println(c.i + “,” + c.j);
}
}
的输出为
(A)1,1
(B)1,2
(C)2,1
(D)2,2
30. 已知:
class B {
int i;
B(int i) {
this.i = i;
}
}
class C extends B {
public static void main(String[] args) {
C c = new C
(1);
System.out.println(c.i);
}
}
的输出为
(A)0
(B)1
(C)编译错误
(D)运行时错误
31. 已知:
class C {
int x;
String y;
public C() {
this(“1”);
System.out.print(“one ”);
}
public C(String y) {
this(1, “2”);
System.out.print(“two ”);
}
public C(int x, String y) {
this.x = x;
this.y = y;
System.out.print(“three ”);
}
public static void main(String[] args) {
C c = new C();
System.out.println(c.x + “ ” + c.y);
}
}
则输出为
(A)1 2 one two three
(B)1 2 three two one
(C)one two three 1 2
(D)three two one 1 2
32. 已知:
class C {
public static void main(String[] args) {
int x = 5;
C c = new C();
c.m(x);
System.out.print(x);
}
public void m(int x) {
System.out.print(x++);
}
}
则输出为
(A)55
(B)56
(C)65
(D)66
33. 已知:
interface I { }
class A implements I { }
class B extends A { }
class C extends B {
public static void main(String[] args) {
B b = new B();
_____________
}
}
在横线处添加哪条语句运行时会产生异常
(A)A a = b;
(B)I i = b;
(C)C c = (C)b;
(D)B d = (B)(A)b;
34. 已知:
class C {
public static void main(String[] args) {
String s = “null”;
if(s == null)
System.out.print(“a”);
else if(s.length() == 0)
System.out.print(“b”);
else
System.out.print(“c”);
}
}
的输出为
(A)a
(B)b
(C)c
(D)null
35. 已知:
class C {
public static void main(String[] args) {
BufferedReader br = null;
try {
br = new BufferedReader(new (“in.txt”));
String temp = null;
while((temp = br.________) !
= null) {
System.out.println(temp);
}
} catch(Exception e) {
} finally {
if(br !
= null) {
br.close();
}
}
}
}
要想打印出in.txt 的全部内容,需要在横线处填写
(A)read()
(B)next()
(C)readLine()
(D)nextLine()
36. 已知:
class Student {
String code, name;
int age;
public boolean equals(Object o) {
if(!
o instance of Student) {
return false;
}
Student s = (Student)o;
return o.code == code && o.age == age;
}
public int hashCode() {
_________________
}
}
横线处应填写
(A)return code.hashCode();
(B)return code.hashCode() + age * 20XXXX;
(C)return code.hashCode() + name.hashCode() + age * 20XXXX;
(D)return super.hashCode();
37. 已知:
class C {
public static void main(String[] args) {
parse(“number”);
}
public static void parse(String s) {
try {
int i = Integer.parseInt(s);
} catch(NumberFormatException e) {
i = 0;
} finally {
System.out.println(i);
}
}
}
则输出为
(A)0
(B)编译错误
(C)运行时抛出ParseException
(D)运行时抛出NumberFormatException
38. 已知:
public interface I {
void m();
}
下面哪个定义是合法的
(A)public interface J extends I {}
(B)public interface J implements I {}
(C)public interface J inherits I {}
(D)public interface J instanceof I {}
39. 已知:
abstract class Shape {
private int x, y;
void setLocation(int x, int y) {
this.x = x;
this.y = y;
}
abstract void draw();
}
class Circle extends Shape {
void draw() {}
}
class Test {
public static void main(String[] args) {
_________________
}
}
下面哪段代码在横线处是合法的
(A)Shape s = new Shape();
s.setLocation(1,1);
s.draw();
(B)Circle c = new Shape();
s.setLocation(1,1);
s.draw();
(C)Shape s = new Circle()
s.setLocation(1,1);
s.draw();
(D)Shape s = new Circle()
s.Shape.setLocation(1,1);
s.Shape.draw();
40. Java 的屏幕坐标系的(0,0)在屏幕的
(A)中心
(B)左上角
(C)左下角
(D)右下角
41. 已知:
class C {
public static void main(String[] args) {
int i = 20XXXX;
System.out.println(i < 8 ?
1.0 :
1);
}
}
(A)1
(B)1.0
(C)8
(D)20XXXX
42. 已知:
class C {
public static void main(String[] args) {
int i = 1;
boolean b = false;
if(b && ++i == 2) {
System.out.print(“first ” + i);
} else {
System.out.print(“second ” + i);
}
}
}
(A)first 1
(B)first 2
(C)second 1
(D)second 2
43. 已知:
class C {
public static void main(String[] args) {
String s = “Welcome to ”;
concat(s);
System.out.print(s);
}
public static void concat(String s) {
s += “Java”;
}
}
则输出为
(A)Welcome to
(B)Welcome to Java
(C)编译错误
(D)运行时异常
44. javax.swing.Timer 将按一定频率产生什么事件
(A)ActionEvent
(B)TimerEvent
(C)ItemEvent
(D)InputEvent
45. 下面哪种布局方式只影响控件的高度,而不影响宽度
(A)BorderLayout 的WEST 和EAST
(B)BorderLayout 的NORTH 和SOUTH
(C)GridLayout
(D)FlowLayout
46. 已知:
class C {
public static void main(String[] args) {
try {
System.out.print(20XXXX + 20XXXX / 0);
} catch(NullPointerException e1) {
System.out.print(“a”);
} catch(RuntimeException e2) {
System.out.print(“b”);
} finally {
System.out.print(“c”);
}
}
}
(A)a
(B)ac
(C)bc
(D)abc
47. 已知:
class C {
public static String s = “c”;
public static void main(String[] args) {
C c = new C();
B b = new B();
System.out.print(C.s);
System.out.print(B.s);
System.out.print(c.s);
System.out.pr