12) }
那些行将引起错误?
A、第3行 B、第6行 C、第7行 D、第8行 26、类Teacher和Student是类Person的子类; (C)
Person p; Teacher t; Student s;
//p, t and s are all non-null.
if(t instanceof Person) { s = (Student)t; } 最后一句语句的结果是:
A、将构造一个Student对象; B、表达式是合法的; C、表达式是错误的; D、编译时正确,但运行时错误。
27、给出下面代码段 (D)
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) int j,k; 8) j=0; k=0;
6
9) t1=new Test(); 10) t2=new Test(j,k); 11) } 12) }
哪行将引起一个编译时错误?
A、line 3 B、line 5 C、line 6 D、line 10 28、对于下列代码: (D)
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) }
12) }
第10行语句将调用哪行语句??
A、line 2 B、line 3 C、line 6 D、line 7
7
29、哪个关键字可以抛出异常? (C)
A、transient B、finally C、throw D、static 30、main()方法的返回类型是: (B)
A、int B、void C、boolean D、static 31、System类在哪个包中? (D)
A、java.util B、java.io C、java.awt D、java.lang 32、对于下列代码: (C)
public class Parent {
public int addValue( int a, int b) { int s; s = a+b; return s; } }
class Child extends Parent { }
下述哪些方法可以加入类Child?
A、int addValue( int a, int b ){// do something...} B、public void addValue (int a, int b ){// do something...}
C、public int addValue( int a ){// do something...} D、public int addValue( int a, int b )throws MyException
8
{//do something...} 33、给出下面代码: (A)
public class test{
static int a[] = new a[10];
public static void main(String args[]) { System.out.println(arr[10]); } }
那个选项是正确的?
A、编译时将产生错误; B、编译时正确,运行时将产生错误;
C、输出零; D、输出空。 34、下面哪些选项是正确的main方法说明?(B)
A、public main(String args[]) B、public static void main(String args[])
C、private static void main(String args[]) D、void main()
Java语言程序设计 二、填空题:
(1)对象串行化可以很容易地扩展成支持Java对象的持续存储或持久存储,它提供了对象从流中重建的补充方式. (2)Vector类的对象是通过capacity和capacityIncrement
9
两个值来改变集合的容量,其中capacity表示集合最多能容纳的元素个数,capacityIncrement表示每次增加多少容量,不是一个一个增加.
(3)下列程序的功能是判断某一年是否为闰年.请在横线处填入适当内容,使程序能够正确运行.
import java.io.*;
public class LeapYear{
public static void main(String arge[]、throws IOException{
InputStreamReader ir; BufferdeReadwe in;
ir=new InputStreamReader(System.in); in=new BufferedReader(ir);
System.out.println(“输入年份是:”); String s= in.readLine(); int year=Integer.parseInt(s);
if year % 4 = = 0 && year % 100! = 0 || year % 400 ==0)
{
System.out.println(\年是闰年.\
}
10