admin 管理员组文章数量: 1184232
2024年3月7日发(作者:下载windows系统)
一、单选题
1、以下程序的调试结果为( )。
public class Outer{
public String name = "Outer";
public static void main(String argv[]){
Inner i = new Inner();
me();
}
private class Inner{
String name = new String("Inner");
void showName(){
n(name);
}
}
}
A.在创建 Inner 类实例的行出现编译错误
B.输出结果 Outer
C.输出结果 Inner
D.编译错误,因 Inner 类定义为私有访问
正确答案:A
2、有关内嵌类以下哪个叙述为假?
A.内嵌类可以被定义为静态成员
B.匿名内嵌类没有对应的字节码文件
C.方法中的内嵌类可以访问方法中定义的常量
D.内嵌类可以访问外部类的成员
正确答案:B
3、以下程序的编译和运行结果为?
abstract class Base{
abstract public void myfunc();
public void another(){
n("Another method");
}
}
public class Abs extends Base{
public static void main(String argv[]){
Abs a = new Abs();
d();
}
public void myfunc(){
n("My Func");
}
public void amethod(){
myfunc();
}
}
A.编译通过,但运行时指示Base 类中存在抽象方法
B.输出结果为 My Func
C.编译指示 Base 类中存在抽象方法
D.编译指示Base 类中的myfunc方法无方法体,没谁会喜欢该方法。
正确答案:B
4、以下代码的调试结果为?
abstract class MineBase {
abstract void amethod();
static int i;
}
public class Mine extends MineBase{
public static void main(String argv[]){
int[] ar = new int[5];
for(i = 0;i < ;i++)
n(ar[i]);
}
}
A.运行错误, i超出数组下标范围
B.编译错误指示"Mine 必须定义为抽象类"
C.编译错误指示"ar 未初始化就使用"
D.输出5个0
正确答案:B
5、如下源文件中的代码:
interface Calculator{
public void calculate();
}
interface Microwave{
public void cook();
}
public class Quiz5_2 implements Calculator,Microwave{
public void calculate() {
n("calculating");
}
public void cook() {
n("cooking");
}
public static void main(String[] args) {
Quiz5_2 x=new Quiz5_2();
ate();
();
}
}
当代码被编译和运行时下列哪条语句是正确的?
A.编译器拒绝类Quiz5_2的定义,因为它实现了两个接口,却没有继承任何类
B.编译成功,输出如下:
calculating
cooking
C.编泽器显示了一个错误,因为接口和类不是在分离的源文件中
D.编译器立即拒绝实现两个接口的企图
正确答案:B
6、以下程序段执行时输入:java Test
则输出结果为( )。
class Test {
public static void main(String args[ ]) {
n(args[0]);
}
}
A.输出 Test
B.无任何输出
C.输出 0
D.产生数组访问越界异常
正确答案:D
7、假设m()方法声明抛出IO异常,哪个写法合法?
m() throws IOException{ }
m(void) throws IOException{ }
m() throw IOException{ }
D.m() throws IOException{ }
正确答案:A
8、当2个实际参数分别为4和0时,以下方法调用的执行结果为:
public void divide(int a, int b) {
try {
int c = a / b;
} catch (Exception e) {
("Exception ");
} finally {
n("Finally");
}
}
A.输出 Finally
B.无输出
C.输出 Exception Finally
D.输出 Exception
正确答案:C
9、下列关键字中用于明确抛出一个异常的是?
y
正确答案:D
二、多选题
1、有关抽象类,以下说法正确的是( )。
A.不能对该类实例化;
B.所有方法均为抽象方法;
C.类定义包含 abstract 关键字。
D.不能派生子类;
正确答案:A、C
2、以下叙述哪个为真?
A.抽象类不能被定义为final
B.局部变量不能添加 static修饰
C.如果有import语句,必须是程序中第一个非注释语句.D.私有成员可被同一包中的所有类访问
正确答案:A、B
3、设有如下代码:
class Base{
public void amethod(int i) { }
}
public class Scope extends Base{
public static void main(String argv[]){
}
//Method Here
}
以下哪个方法可插入//Method 处?
void amethod(String i) { }
void amethod(long i) { }
C. public void amethod(int i) throws Exception {}
D. public void amethod(int i) { }
正确答案:A、B、D
4、下列两个类分别定义在各自文件中?
1. public class Testl {
2. public float aMethod(float a, float b) throws
3. IOException {...
4. }
5. }
1. public class Test2 extends Testl {
2.
3. }
在类Test2的第2行能插入以下哪个方法?
int aMethod(int a, int b) throws Exception {...}
aMethod(float a, float b) {...}
float aMethod(float p, float q) {...}
float aMethod(float a, float b) throws Exception {...}
正确答案:A、C
5、下面的代码:
class E1 extends Exception{ };
class E2 extends E1{ }
public class Quiz6_3 {
public void f(Boolean flag) throws E1{
//一一X一一
}
}
下列的语句,哪—个可以放到--X--位置,而且保证编译成功?
new E2();
new Exception();
new Error();
new E1();
正确答案:A、D
三、填空题
1、用_____修饰符修饰的方法是抽象方法。
正确答案:abstract
2、用___________修饰符修饰的成员只能在本类中直接访问.
正确答案:private
3、写出程序的运行结果
public class test02{
public static void main(String args[]) {
String str = null;
try {
if (() == 0) {
("The");
}
(" Cow");
} catch (Exception e) {
(" and");
(0);
} finally {
(" Chicken");
}
n(" show");
}
}
正确答案:and
4、写出程序运行结果
public class Test4 {
static void method(int x[]) {
try { x[1]=x[1]+x[2];
} catch (ArrayIndexOutOfBoundsException e) {
("out of range");
} finally {
("come here!");
}
}
public static void main(String args[]) {
int a[]={3,5,7,6,8};
method(a);
(a[1]);
}
}
正确答案:come here!12
版权声明:本文标题:Java程序设计单元测试三与答案 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1709792832a546435.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论