9、【
单选题
】 类Parent、Child定义如下:
1\. public class Parent
2\.{ public float aFun(float a, float b) throws
3\. IOException { }
4\.}
5\.public class Child extends Parent{
6\.
7\.}
将以下哪种方法插入行6是不合法的。( )
[2分]
、
float aFun(float a, float b){ }
、
public int aFun(int a, int b)throws Exception{ }
、
public float aFun(float p, float q){ }
、
public int aFun(int a, int b)throws IOException{ }
答案:
10、【
单选题
】 给出下面代码,关于该程序以下哪个说法是正确的?( )
public class Person{
static int arr[] = new int[5];
public static void main(String a[])
{
System.out.println(arr[0]); }
}
[2分]
、
编译时将产生错误
、
编译时正确,运行时将产生错误
、
输出零
、
输出空
答案:
11、【
单选题
】 在编写Java Applet程序时,需在程序的开头写上( )语句。
[2分]
、
import java.awt.* ;
、
import java.applet.Applet ;
、
import java.io.* ;
、
import java.awt.Graphics ;
答案:
12、【
单选题
】 下列类定义中哪些是合法的抽象类的定义?( )
[2分]
、
abstract Animal{abstract void growl();}
、
class abstract Animal{abstract void growl();}
、
abstract class Animal{abstract void growl();}
、
abstract class Animal{abstrac t void growl(){System.out.println(“growl”);};}
33、【
简答题】 以下程序段的输出结果为 。
public class TestArray
{
public static void main(String args[ ]){
int i , j ;
int a[ ] = { 5,9,6,8,7};
for ( i = 0 ; i < a.length-1; i ++ ) {
int k = i;
for ( j = i ; j < a.length ; j++ )
if ( a[j]<a[k] ) k = j;
int temp =a[i];
a[i] = a[k];
a[k] = temp;
}
for ( i =0 ; i<a.length; i++ )
System.out.print(a[i]+" ");
System.out.println( );
}
}
[4分]
解析: a .public class Hello{
public static void main(string args[])
{System.out.println(“Hello World!”);}
}
b. import java.awt.Graphics;
import.java.applet.Applet;
public class HelloApplet extends Applet{
public void paint(Graphics g)
{g.drawString(“Hello World!”,20.20);
}
}
35、【
简答题】 写出以下程序的运行结果。
import java.io.*;
public class ATest{
public static void main(String args[]) {
SubClass sb = new SubClass( );
System.out.println(sb.fun( ));
}
}
class SuperClass{
int a =24 , b =5 ;
}
class SubClass extends SuperClass{
int fun( ) { return a%b; }
[4分]
37、【
简答题】 写出以下程序的运行结果。
public class TryCatchFinally{
static void Proc( int sel ){
try{
if( sel==0 ){System.out.println("no Exception ");
return;}
else if( sel==1 ){ int i=0; int j=4/i;}
}
catch( ArithmeticException e ) {
System.out.println("Catch "); }
catch( Exception e ) {
System.out.println("Will not be executed");}
finally{
System.out.println("finally"); }
}
public static void main( String args[] ){
Proc( 0 ); Proc( 1 ); }
}
[4分]
解析: no Exception
finally
Catch
finally
38、【
简答题】 阅读程序段,回答问题:
public class ClassA{
public void method1(int i){}
public void method2(int i){}
public static void method3(int i){}
public static void method4(int i){}
}
public class ClassB extends ClassA{
public static void method1(int i){}
public void method2(int i){}
public void method3(int i){}
public static void method4(int i){}
}
ClassB中(method1、method2、method3、method4)四个方法,方法
_________ 覆盖了父类方法;方法 _________ 隐藏了父类方法。
[4分]