复习题集答案

1. C 2. A 3. B D 4. C 5. C 6. ABCD 7. B 8. B 9. C 10. D
11. BC 12. BCD 13.CD 14. B 15. CE 16.B 17. C 18.C 19. C 20. A
21. B 22. AC 23. D 24. CD
1、下列对Java中的继承描述错误的说法是(C)。
A.子类至少有一个基类
B.子类可作为另一个子类的基类
C.子类可以通过this关键字来访问父类的私有属性
D.子类继承父类的方法访问权限保持不变
2、构造方法是否可被重写和重载(A)。
A.不能重写,可以重载
B.可以重写,不能重载
C.不能重写,不能重载
D.可以重写,可以重载
3、下列属于方法重载好处的是(BD)。
A.实现多态
B.方法名的复用
C.提高程序运行速度
D.使用方便,提高可读性
4、面向对象方法的多态性是指(C)。
A.一个类可以派生出多个特殊类
B.一个对象在不同的运行环境中可以有不同的变体
C.拥有相同父类或接口的不同对象可以以适合自身的方式处理同一件事
D.一个对象可以是由多个其他对象组合而成的
5、 Dog是Animal的子类,下面代码错误的是(C)。
A.Animal a = new Dog();
B.Animal a = (Animal )new Dog();
C.Dog d = (Dog)new Animal();
D.Object o = new Dog() ;
6、下面定义Java的常量,正确的是(ABCD)。
A.public static final double PI = 3.14;
B.public final static double PI = 3.14;
C.final public static double PI = 3.14;
D.static public final double PI = 3.14;
7、下面代码的运行结果是(B) 。 public class Car {
public void run(){ System.out.println("汽车在跑"); } } public class Benz extends Car { public void run(){ System.out.println("奔驰在跑"); } } public static void main(String[] args) { Car car = (Car)( new Benz() ); car. run(); }
A. 汽车在跑
B. 奔驰在跑
C. 无法编译
D. 运行时将抛出异常
8、下列代码的输出结果是(B)。 public class Example { String str = new String("good"); char[] ch = {'a','b','c'}; public static void main(String[] args) { Example ex=new Example(); ex.change(ex.str,ex.ch); System.out.print(ex.str+" and "); System.out.println(ex.ch); } public void change(String str,char ch[]){ str="test ok"; ch[0]='g'; } } A.good and abc
B.good and gbc
C.test ok and abc
D.test ok and gbc
9、能与public void methodA(){ }方法形成重载的有(C)。
A.private void methodA(){ }
B.private int methodA(){ return 1;}
C.public void methodA(int a){ }
D.public void methodA() throws Exception{ }
10、子类中能与父类public void methodA(int a){ }方法形成重写的有(D) 。
A.public int methodA(int a){return 1;}
B.public void methodA(int a) throws Exception{ }
C.private void methodA(int a){ }
D.public

void methodA(int b){ }
11、关于构造方法,下面说法错误的是(BC)。
A.父类只有一个带参的构造方法,子类必须显示声明带参构造方法
B.子类无参构造方法中没有写super();不会调用父类无参构造方法
C.子类无参构造方法不可以用super(int a);调用父类对应的带参构造方法
D.实例化一个类的对象时,一定会先调用https://www.360docs.net/doc/0113486573.html,ng.Object的构造方法
12、阅读下面的代码,B类注释处可以放置的方法是(BCD)。 class A { public void method(int a,float b){ //一些声明等等 } } public class B extends A { // 这里放置方法 }
A.private void method(int i,float a) {…}
B.public void method(int i,float f) {…}
C.public void method() {…}
D.private int method(float f,int b) {…}
13、关于Java的继承,下面说法错误的是(CD)。
A.接口可以继承接口
B.子类不可以继承父类的私有属性和私有方法
C.所有类都是https://www.360docs.net/doc/0113486573.html,ng.Object的子类,但是不可以这样写:public class Earth extends Object{}
D.一个类不可以继承(extends)另一个类,同时又实现(implements)一个接口
14、Thing是一个类,下面的代码可以产生(B)个Thing类型的对象。 Thing item; Thing stuff; item = new Thing();
Thing entity = new Thing();
A.1 B.2 C.3 D.4
15、阅读下面的代码,正确的说法是(CE)。 class Foo {
int num;
Baz comp = new Baz();
}
class Bar {
boolean flag;
}
class Baz extends Foo {
Bar thing = new Bar();
double limit;
}
A.Bar是Baz子类
B.Foo 包含 Bar
C.Baz是Foo子类
D.Foo是Baz子类
E.Baz包含Bar

16、try {B}里有一个return语句,那么紧跟在这个try后的finally {}里的代码会不会被执行,什么时候被执行?

A不会执行
B会执行,在return前执行
C会执行,在return后执行
D会执行,可能在return前执行,也可能在return后执行
17、这段代码的输出结果是(C)。
try{
System.out.print("try,");
return;
} catch(Exception e){
System.out.print("catch,");
} finally {
System.out.print("finally");
}
A.try,
B.try,catch,
C.try,finally
D.try, catch,finally
18、这个方法的返回值是(C)。
public int count() {
try{
return 5/0;
} catch(Exception e){
return 2*3;
} finally {
return 3;
}
}

A.0
B.6
C.3
D.程序错误
19、王强使用log4j的配置文件如下,
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out

log4j.rootLogger=info, stdout, file
他在程序中这样编写,将会输出的日志信息是(C)。
logger.debug("记录debug日志");
https://www.360docs.net/doc/0113486573.html,("记录info日志");

A.记录debug日志
记录info日志
B.记录debug日志
C.记录info日志
D.程序错误,无法输出日志
20、下

面的异常处理代码的输出结果是(A)。
public static void main(String[] arg){
try{
int result = 6/0;
System.out.print("try,");
} catch(ArithmeticException e1) {
System.out.print("ArithmeticException异常,");
throw new Exception();
} catch(Exception e2) {
System.out.print("Exception异常,");
} finally {
System.out.print("finally");
}
}
A.程序编译错误
B.ArithmeticException异常,finally
C.ArithmeticException异常, Exception异常, finally
D.try, ArithmeticException异常, Exception异常, finally
21、阅读下面代码,将会输出(B)。
public class Testa {
Integer a = new Integer(10);
Integer b = new Integer(10);
public static void main (String[ ] args){
Testa testA = new Testa();
if (testA.a==testA.b){
System.out.print("很");
}
if (testA.a.equals(testA.b)){
System.out.print("好");
}
}
}
A. 很
B.好
C.很好
D.抛出NullPointerException异常
编译错误

22、根据下面的代码,
String s = null;
会抛出NullPointerException异常的有(AC)。

A.if( (s!=null) & (s.length()>0) )
B.if( (s!=null) && (s.length()>0) )
C.if( (s==null) | (s.length()==0) )
D.if( (s==null) || (s.length()==0) )
23、编译运行下列程序会发生(D)的情况。
public class Mystery {
String s;
public static void main(String args[ ] ) {
Mystery m =new Mystery();
m.go();
}
public void Mystery() {
s ="Constructor";
}
private void go(){
System.out.println(s);
}
}
A.可以编译,运行时会抛异常
B.可以编译运行,但是控制台上什么都不输出
C.输出“constructor”
D.输出“null”
24、关于Java的异常和异常处理,下面说法错误的是(CD)。

A.try/catch/finally块里都可以嵌套try/catch/finally
B.一个try可以对应多个catch
C.如果发生的异常没有被捕捉,异常将被系统忽略
D.异常处理时可以只用try块。

相关文档
最新文档