JAVA考核题-面向对象选择题(答案)

发布时间 : 星期二 文章JAVA考核题-面向对象选择题(答案)更新完毕开始阅读

技术改变世界 创新驱动发展

Sytem.out.print(ex.ch); }

public void change(String str,charch[]){ str=\ ch[0]='g'; } }

A.good and abc

B.good and gbc D.test ok and gbc

C.test ok and abc

33.下列哪些语句关于内存回收的说明是正确的?( B )

A.程序员必须创建一个线程来释放内存 B.内存回收程序负责释放无用内存 C.内存回收程序允许程序员直接释放内存 D.内存回收程序可以在指定的时间释放内存对象

34.MAX_LENGTH是int型public成员变量, 变量值保持为常量100,用简短语句定义这个变量。( CD )

A、 public int MAX_LENGTH=100; B、 final int MAX_LENGTH=100; C、 final public int MAX_LENGTH=100; D、 public final int MAX_LENGTH=100; 35.给出下面代码:

1) class Parent { 2} private String name; 3} public Parent(){} 4} }

5) public class Child extends Parent { 6} private String department; 7} public Child() {}

8} public String getValue(){ return name; }

您的未来就是我们的未来

技术改变世界 创新驱动发展

9} public static void main(String arg[]) { 10} Parent p = new Parent(); 11} } 12} }

那些行将引起错误? ( D ) A、 第3行

B、 第6行

C、 第7行

D、 第8行

36.类Teacher和Student是类Person的子类; Person p; Teacher t; Student s;

//p, t and s are all non-null.

if(t instanceof Person) { s = (Student)t; }

最后一句语句的结果是:( B ) A、 将构造一个Student对象; C、 表达式是错误的;

B、 表达式是合法的;

D、 编译时正确,但运行时错误。

解析:考查instanceof和继承中的强制转换。t instanceof Person 表达式是正确的。

s = (Student)t;这句转换编译是错误的。 37.给出下面代码段

1) public class Test { 2) int m, n; 3) public Test() {}

4) public Test(int a) { m=a; }

5) public static void main(String arg[]) { 6) Test t1,t2; 7) intj,k; 8) j=0; k=0; 9) t1=new Test(); 10) t2=new Test(j,k); 11) }

您的未来就是我们的未来

技术改变世界 创新驱动发展

12) }

哪行将引起一个编译时错误?( D)

A、 line 3 B、 line 5

C、 line 6

D、 line 10

38.对于下列代码:

1) class Person {

2) public void printValue(int i, int j) {//... } 3) public void printValue(int i){//... } 4) }

5) public class Teacher extends Person { 6) public void printValue() {//... } 7) public void printValue(int i) {//...} 8) public static void main(String args[]){ 9) Person t = new Teacher(); 10) t.printValue(10); 11) }

第10行语句将调用哪行语句? ( D )

A、 line 2

B、 line 3

C、 line 6

D、 line 7

39.System类在哪个包中? ( D )

A、 java.util B、 java.io

C、 java.awt

40.对于下列代码:

public class Parent {

public intaddValue( int a, int b) { int s; s = a+b; return s; } }

class Child extends Parent { }

您的未来就是我们的未来

D、java.lang

技术改变世界 创新驱动发展

下述哪些方法可以加入类Child? ( CD )

A、 intaddValue( int a, int b ){// do something...}

B、 public void addValue (int a, int b ){// do something...} C、 public intaddValue( int a ){// do something...}

D、 public intaddValue( int a, int b )throws MyException {//do something...} 解析:A选项不符合一大;B选项返回值类型不匹配;C选项为自己的方法;D选项异常更明确。

41.看下面一段程序:

class Aclass{ void go(){

System.out.println(\ } }

public class Bclass extends Aclass{ void go{

System.out.println(\ }

public static void main(String args[]){ Aclass a=new Aclass(); Aclass a1=new Bclass(); a.go(); a1.go(); }

以上程序运行结果是:( C ) A、 AclassAclass C、 AclassBclass

B、 BclassBclass D、 BclassAclass

42.运行下列程序,会产生什么结果:( B) class Outer1{ private int a;

您的未来就是我们的未来

联系合同范文客服:xxxxx#qq.com(#替换为@)