2024年5月11日发(作者:)
JAVA语言程序设计期末考试试题及答案3应考必备题库
一、单项选择题
1、如下哪个是Java中的标识符
A、public B、super
2、如下哪个是Java中的标识符
A、fieldname B、super
A、s += "books";
C、int len = ;
A、name
C、3number D、width
C、3number D、number
B、s = s + 100;
D、String t = s + “abc”;
C、false D、good
3、已知如下定义:String s = "story"; 下面哪个语句不是合法的
4、如下哪个是Java中有效的关键字
B、hello
5、下面的代码段执行之后count的值是什么
int count = 1;
for int i = 1; i <= 5; i++ {
}
count += i;
、5 B、1 C、15 D、16
D、static
D、static
6、定义一个类,必须使用的关键字是
A、public
A、public
语句是
A、b; B、b,"North";
C、b,"South"; D、p,"North";
9、声明并创建一个按钮对象b,应该使用的语句是
A、Button b=new Button; B、button b=new button;
C、Button b=new b; D、“确定”;
10、Frame对象默认的布局管理器是
A、FlowLayout
C、CardLayout
A、import .;
C、import .;
A、import .;
B、BorderLayout
D、null
B、class
B、class
C、interface
C、interface
7、定义一个接口必须使用的关键字是
8、如果容器组件p的布局是BorderLayout,则在p的下边中添加一个按钮b,应该使用的
11、下列哪一个import命令可以使我们在程序中创建输入/输出流对象
B、import .;
D、import .;
B、import .;
12、下面哪一个import命令可以为我们提供编写网络应用程序的类
C、import .; D、import .;
B、FileOutputStream
13、如果需要从文件中读取数据,则可以在程序中创建哪一个类的对象
A、FileInputStream
C、DataOutputStream D、FileWriter
二、填空题
1、如果将类MyClass声明为public,它的文件名称必须是才能正常编译;
2、Java程序中的单行注释符是 ; ;
8、当声明一个数组int arr = new int5; 时,这代表这个数组所保存的变量类型是int,
数组名是arr,数组的大小为5,数组元素下标的使用范围是0到4;
9、假设x=13,y=4,则表达式x%y = 0的值是true,其数据类型是boolean;
10、异常处理是由try、catch和finally块三个关键所组成的程序块;
11、以下程序段的输出结果是三角形
int x = 5, y = 6, z = 4;
if x + y > z && x + z > y && z + y > x
"三角形";
else
"不是三角形";
12、下面程序段的执行结果是6 5 4 3 2
int a = { 2, 3, 4, 5, 6 };
for int i = - 1; i >= 0; i--
+ "";
三、程序阅读题
1、以下程序的输出结果为_
Peter is 17 years old___;
public class Person {
String name;
int age;
public PersonString name, int age {
= name;
= age;
}
public static void mainString args {
Person c = new Person"Peter", 17;
+ " is " + + " years old";
}
}
2、以下程序的输出结果为__课程号:101 课程名:ASP 学分:3___;
public class Course {
private String cNumber;
private String cName;
private int cUnit;
public CourseString number, String name, int unit {
}
}
cNumber = number;
cName = name;
cUnit = unit;
public void printCourseInfo {
}
"课程号:" + cNumber + " 课程名:" + cName + " 学分:" + cUnit;
class CourseTest {
}
public static void mainString args {
}
Course c;
c = new Course"101", "ASP", 3;
;
3、以下程序的输出结果为__汤姆猫体重:斤___;
public class Tom {
}
private float weight;
private static String
name
;
public void setWeightfloat weight {
}
private void out {
}
public static void mainString args {
}
= "汤姆猫";
Tom cat = new Tom;
20;
;
+ "体重:" + weight + "斤";
= weight;
4、以下程序的输出结果__;
public class Father {
String name, address, tel;
int age;
public FatherString name, int age {
}
void out {
}
"姓名:" + name;
" 年龄:" + age;
= name;
= age;
}
void outOther {
}
" 家庭住址:" + address;
" 电话:" + tel;
class Son extends Father {
}
String school;
public SonString name, int age {
}
void out {
}
public static void mainString args {
}
Son son = new Son"Tom", 15;
= "金水区";
= "九中";
= ;
;
;
;
" 学校:" + school;
supername, age;
5、下列程序的运行结果是__12345____;
public class MyClass {
}
int a = { 1, 2, 3, 4, 5 };
void out {
}
public static void mainString args {
}
MyClass my = new MyClass;
;
for int j = 0; j < ; j++
+ "";
四、简答题
1、简述Java中异常处理的机制
答:首先Java的异常是面向对象的;一个Java的Exception是一个描述异常情况的对象.
当出现异常情况时,一个Exception对象就产生了,并放到异常的成员函数里;
Java的异常处理是通过5个关键词来实现的:try,catch,throw,throws和finally;
1.异常处理:在Java语言的错误处理结构由try,catch,finally三个块组成;其中
try块存放将可能发生异常的Java语言,并管理相关的异常指针;catch块紧跟在try块
发布评论