试题编号:
重庆邮电大学××××学年××学期
一、选择题(每题1分,共30分)
1、下列哪些语句关于内存回收的说明是正确的? ()
A:程序员必须创建一个线程来释放内存; B:内存回收程序负责释放无用内存; C:内存回收程序允许程序员直接释放内存; D:内存回收程序可以在指定的时间释放内存对象。
2、有下列程序:
public class aa{
public static void main(String[ ] args) {
String s = "18.03";
try {
double number1 = Double.parseDouble(s);
System.out.print(number1);
int number2 = Integer.parseInt(s);
System.out.println(" " + number2);
}catch(NumberFormatException nfe) {
System.out.println(" Sorry");
}catch(Exception e){
}
}
}
执行结果是()
A:18.03 B:Sorry
C:18.03 Sorry D:出现编译错误
3、下面哪个选项可以将“hello”字符写入文件file.txt的末尾?()
A:OutputStream out= new FileOutputStream ("file.txt");
Out.writeBytes ("hello");
B:OutputStream os= new FileOutputStream ("file.txt", true); DataOutputStream out = new DataOutputStream(os);
out.writeBytes ("hello");
C:OutputStream os= new FileOutputStream ("file.txt");
DataOutputStream out = new DataOutputStream(os);
out.writeBytes ("hello");
D:OutputStream os= new OutputStream ("file.txt", true); DataOutputStream out = new DataOutputStream(os);
×××××试卷第1页(共××页)
out.writeBytes ("hello");
4、3. 在启动Java应用程序时可以通过main( )方法一次性地传递多个参数。如果传递的参数有多个,可以用空格将这些参数分割;如果某一个参数本身包含空格,可以使用什么符号把整个参数引起来()。
A:'' B:“”
C:** D://
5、在Java中,存放字符串常量的对象属于()类对象
A:Character B:String
C:StringBuffer D:Vector
6、设有以下程序段,执行后,屏幕输出()
String s1 = "I love "+"China";
String s2 = new String(s1);
if (s1 == s2)
System.out.println("==");
if (s1.equals(s2) == true)
System.out.print("equals");
A:equals B:==
C:== equals D:不输出
7、哪个不是Java语言的特点( )
A:面向对象 B:自动检查语法错误
C:跨平台 D:解释执行
8、为AB类的一个无形式参数无返回值的方法method书写方法头,使得使用类名AB作为前缀就可以调用它,该方法头的形式为( )
A:static void method( ) B:public void method( )
C:final void method( ) D:abstract void method( )
9、下面哪个单词是Java语言的关键字()
A:Double B:string
C:this D:bool
10、下列叙述中,错误的是 ( )
A:内部类的名称与定义它的类的名称可以相同 B:内部类可用abstract修饰
C:内部类可作为其他类的成员 D:内部类可访问它所在类的成员
11、在Java 语言中,如果你有下面的类定义:
abstract class Shape{
abstract void draw();
}
class Square extends Shape{
}
以下描述正确的是()
A:一切成功编译 B:Shape可以编译,Square不能编译
×××××试卷第2页(共××页)
C:Square可以编译,Shape不能编译 D:Square,Shape都不能编译
12、在Java中,用package说明一个包时,该包的层次结构必须是()
A:与文件的结构相同 B:与文件的目录层次相同
C:与文件的类型相同 D:与文件大小相同
13、11. 下面哪条语句不能定义一个float型的变量f1()
A:float f1= 3.1415E10 B:float f1=3.14
C:float f1=3.1415F D:f1=3.14F
14、编译Java Application 源程序文件将产生相应的字节码文件,这些字节码文件的扩展名为( )。
A:java B:class
C:html D:exe
15、设 x = 1 , y = 2 , z = 3,则表达式 y+=z--/++x 的值是( )
A:3 B:3.5
C:4 D:5
16、分析下列Java代码:
class A{
public static void main(String[ ] args){
method( );
}
static void method( ){
try{
System.out.println("Hello");
System.exit(0);
}finally{
System.out.println("good-bye");
}
}
}
编译运行后,输出结果是()
A:Hello B:good-bye
C: Hello
good-bye D:代码不能编译
17、在Java中,不属于整数常量的是()
A:100 B:100L
C:0X100 D:100.0
18、下列构造方法的调用方式中,正确的是()
A:按照一般方法调用 B:由用户直接调用
C:可通过new自动调用 D:被系统调用
19、以下哪个关键字可以用来对对象加互斥锁?()
A:transient B:synchronized
×××××试卷第3页(共××页)
C:serialize D:static
20、在Java中,以下叙述不正确的是()
A:构造方法名与类名相同
B:构造方法不是用来完成初始化的
C:构造方法由 new 操作调用,而不能被用户直接调用
D:构造方法没有返回类型
21、在Java中,某类方法使用下列()访问修饰符修饰后,可以被其的子类访问 A:private B:protected
C:void D:friendly
22、下面程序输出结果是()
public class Delta {
static boolean foo(char c) {
System.out.print(c);
return true;
}
public static void main( String[] argv ) {
int i =0;
for ( foo('A'); foo('B')&&(i<2); foo('C')){
i++ ;
foo('D');
}
}
}
A:ABDCBDCB B:ABCDABCD
C:编译错误 D:运行时异常
23、Java编程所必须的默认引用包为()
A:java.sys包 B:https://www.doczj.com/doc/1a5748778.html,ng包
C:java.new包 D:以上都不是
24、类Worker是类Person的子类,Worker构造方法中有一句"super( );",该语句是什么意思()
A:调用类Worker中定义的super( )方法
B:调用类Person中定义的super()方法
C:调用类Person的构造函数
D:语法错误
25、在Java里,下列选项()不是实现面向对象思想的机制
A:封装 B:继承
C:多态 D:数据类型转换
26、10. 下面哪个范围是char型的取值范围()
A: -256 ~ 255 B:- (2^15) ~ (2^15)-1
C:\u0000’ ~ ‘\uffff’ D:0~32767
×××××试卷第4页(共××页)
27、下面哪条语句定义了3个元素的数组()
A: int [ ] a={20,30,40}; B:int a [ ]=new int(3);
C:int [3] array; D:int [ ] arr;
28、设有下面两个赋值语句:
x1=Integer.parseInt("123");
x2=Integer.valueOf("123").intValue();
下述说法正确的是()
A:x1为int型变量,x2为Integer类的对象
B:x2为int型变量,x1为Integer类的对象
C:x1、x2均为Integer类的对象
D:x1、x2均为int型变量
29、考虑下列JAVA代码:
class A{
public static void main(String[ ] args){
try{
System.out.println("Hello,World!");
}
}
}
这段代码错误的原因是()。
A:没有catch和finally块
B:没有抛出异常的代码不能出现在try代码块内
C:如果没有catch块而使用try,main( )会总是抛出异常
D:class A没有throws IOException
30、下列运算结果为float的是()
A:100/10 B:100*10
C:100.0+10 D:100-10
二、判断题(每题1分,共20分)
31、String str; System.out.println(str.length()); 以上语句运行的结果是显示0
32、拥有abstract方法的类是抽象类,但抽象类中可以没有abstract方法
33、Jframe是一个程序的主窗口,它是顶级容器
34、Java有垃圾回收机制,内存回收程序可在指定的时间释放内存对象。
35、if("Hunan".indexOf('n')==2) System.out.println("true"); 以上语句运行的结果是显示true
36、用Javac编译Java源文件后得到代码叫字节码。()
37、Java的源代码中定义几个类,编译结果就生成几个以.class为后缀的字节码文件
38、一个类中,只能拥有一个构造器方法
39、程序中抛出异常时(throw …),只能抛出自己定义的异常对象。
40、if(true){int i=17;}
System.out.println(i);
×××××试卷第5页(共××页)
运行此程序的结果是输出17
41、Float aFlost=new Float(2.3); Double aDouble=new Double(2.3); if(aFloat==aDouble) System.out.println("Equal"); else System.out.println("Not Equal"); 以上语句运行的结果是显示Equal
42、Java程序里,创建新的类对象用关键字new,回收无用的类对象使用关键字free。
43、一个异常处理中 finally语句块只能有一个或者可以没有。()
44、构造函数用于创建类的实例对象,构造函数名应与类名相同,返回类型为void。
45、实现一个接口,则在类中一定要实现接口中的所有方法。()
46、在Java中对象可以赋值,只要使用赋值号(等号)即可,相当于生成了一个各属性与赋值对象相同的新对象
47、编译语句int aInt=66666不会出现编译错误
48、在异常处理中,若try中的代码可能产生多种异常则可以对应多个catch语句,若catch中的参数类型有父类子类关系,此时应该将父类放在后面,子类放在前面。
49、接口中的所有方法都可以没有被实现
50、float x=26f; int y=26; int z=x/y; 以上语句能正常编译和运行
三、程序阅读题(共20分)
51、写出下面的程序编译、运行后的结果。
public class Test{
public static void main(String args[]) {
new Student("Tom",'m',90,88);
new Student("Jack",'m',66,89);
new Student("Mary",'f',76,86);
System.out.println("name\tsex\tchinese\tenglish");
Student.print();
}
}
class Student {
protected String name;
protected char sex;
protected int chinese;
protected int english;
protected Student next;
static Student list;
Student(String name, char sex, int chinese,int english) {
https://www.doczj.com/doc/1a5748778.html,=name;
this.sex=sex;
this.chinese=chinese;
this.english=english;
×××××试卷第6页(共××页)
this.next=list;
list=this;
}
static void print() {
Student friend=list;
if(friend==null)
System.out.println("The list is empty.");
else {
do{
System.out.println(friend.toString());
friend=friend.next;
}while(friend!=null);
}
}
public String toString() {
return new String(name+"\t"+sex+"\t"+chinese+"\t"+english); }
}
52、写出下面的程序编译、运行后的结果
import java.io.*;
public class abc
{
public static void main(String args [ ])
{
AB s = new AB("Hello!","I love JAVA.");
System.out.println(s.toString( ));
}
}
class AB {
String s1;
String s2;
public AB(String str1, String str2)
{
s1 = str1;
s2 = str2;
}
public String toString( )
{
return s1+s2;
}
×××××试卷第7页(共××页)
}
53、读程序,写出正确的运行结果。
public class Father{
int a=100;
public void miner(){
a--;
}
public static void main(String[] args){
Father x = new Father();
Son y = new Son();
System.out.println(y.a);
System.out.println( y.getA());
y.miner();
System.out.println(y.a);
System.out.println(y.getA());
}
}
class Son extends Father{
int a = 0;
public void plus(){
a++;
}
public int getA() {
return super.a;
}
}
54、以下程序的输出结果为_____。
Public class Tom {
private float weight;
private static String name;
public void setWeight(float weight) {
this.weight = weight;
}
private void out() {
System.out.println(name + "体重:" + weight + "斤");
}
public static void main(String[] args) {
×××××试卷第8页(共××页)
https://www.doczj.com/doc/1a5748778.html, = "汤姆猫";
Tom cat = new Tom();
cat.setWeight(20);
cat.out();
}
}
55、指出以下程序的错误,并改正:
public class Test {
public static void main(String[] args) {
MyClass obj=new MyClass();
https://www.doczj.com/doc/1a5748778.html,+=”,World!”;
System.out.println(https://www.doczj.com/doc/1a5748778.html,);
}
}
class MyClass {
public String Info=”Hello”;
public MyClass(String Info)
{
https://www.doczj.com/doc/1a5748778.html,=Info;
}
}
56、import java.io.* ;
public class Reverse
{ public static void main(String args[ ])
{ int i , n =10 ;
int a[ ] = new int[10];
for ( i = 0 ; i < n ; i ++ )
try {
BufferedReader br = new BufferedReader(
new InputStreamReader(System.in));
a[i] = Integer.parseInt(br.readLine( )); // 输入一个整数 } catch ( IOException e ) { } ;
for ( i = n-1 ; i >= 0 ; i ―― )
System.out.print(a[i]+" ");
System.out.println( );
}
}
57、以下程序段的输出结果为______________。
Public class TestArray
{
×××××试卷第9页(共××页)
public static void main(String args[ ]){
int I , j ;
int a[ ] = { 5,9,6,8,7};
for ( I = 0 ; I < a.length-1; I ++ ) {
int k = I;
for ( j = I ; j < a.length ; j++ )
if ( a[j] int temp =a[i]; a[i] = a[k]; a[k] = temp; } for ( I =0 ; i System.out.print(a[i]+" "); System.out.println( ); } } 58、阅读下面的程序,并回答问题 import javax.swing.*; import java.awt.*; import java.awt.event.*; public class MenuTest extends JFrame{ JTextArea theArea; public MenuTest(){ super("MyMenu"); Container contentPane = this.getContentPane(); theArea = new JTextArea( ); theArea.setText("The first snow came,\nHow beautiful it was!"); theArea.setLineWrap(true); contentPane.add(new JScrollPane(theArea),BorderLayout.CENTER); JMenu fontMenu = new JMenu("Font"); JMenuItem fontSize= new JMenuItem("Size"); fontSize.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { String sizeString=JOptionPane.showInputDialog( "字号大小" ); int fontSize=Integer.parseInt(sizeString); ×××××试卷第10页(共××页) theArea.setFont( new Font("楷体_gb2312",Font.PLAIN,fontSize)); } }); fontMenu.add(fontSize); JMenuItem exit= new JMenuItem("Exit"); exit.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { System.exit(0); } }); fontMenu.add(exit); JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); menuBar.add(fontMenu); this.setSize(300,200); this.setVisible(true); } public static void main(String[] args){ new MenuTest(); } } (1)图示程序运行后的图形界面。 (2)用文字描述点击菜单项“Size”后,程序的执行过程和效果。 59、以下程序段的输出结果为________。 Public class TestArray { public static void main(String args[ ]){ int I , j ; int a[ ] = { 5,9,6,8,7}; for ( I = 0 ; I < a.length-1; I ++ ) { int k = I; for ( j = I ; j < a.length ; j++ )