JAVA经典试卷(理工)

一、判断题(本大题共20小题,每小题1分,总计20分)

1.final类能派生子类。

2.子类要调用父类的方法,必须使用super关键字。

3.Java类可以有多个父类。

4.如果p是父类Parent的对象,而c是子类Child的对象,则语句c = p是不正确的。

5.子接口继承父接口的所有常量和方法。

6.Java程序里,创建新的类对象用关键字new,回收无用的类对象使用关键字free。

7.类的构造方法可以是任何类型的。

8.抽象方法必须在抽象类中,但抽象类中的方法可以不都是抽象方法。

9.Java的字符类型采用的是ASCII编码。

10.Java的各种数据类型占用固定长度,与具体的软硬件平台环境无关。

11.Java中数组的元素可以是简单数据类型的量,也可以是某一类的对象

12.一个线程对象的具体操作是由run()方法的内容确定的。

13.一个类如果实现了某个接口,那么它必须重写该接口中的所有方法。

14.对于final修饰的成员变量,不占用内存。

15.Java的源代码中定义几个类,编译就生成几个以.class为后缀的字节码文件。

16.静态方法不能以任何方式引用this和super关键字。

17.抽象方法只需声明,不需实现。

18.实例变量可以通过类名访问。

19.创建数组后,系统会给每个数组元素一个默认的值0。

20.如果一个Java源文件中有多个类,那么最多有一个类是public类。

二、单项选择题(本大题共10小题,每小题1分,总计10分)

1. 关于Java语言叙述错误的是:(   )。  

A.Java语言具有跨平台性 

  B.Java是一种面向对象的语言 

C.Java语言中的类可以多继承  

D.Java的垃圾收集机制自动回收程序已不再使用的对象

2. 下列最终属性 i 的定义中,正确的是(   )。  

   A.static final int i=100;   B.final int i=1.2;   

  C.final  i='w';             D.final char i; 

3. 下列类定义中,不正确的是(    )。  

   A.class x { .... }     

B.class x extends y { .... }  

C.static class x implements y1,y2 { .... }

   D. public class x extends Applet { .... } 

4. 以下有关类的继承的叙述中,正确的是:(   )。 

A.子类能直接继承父类所有的非私有属性,也可通过接口继承父类的私有属性    

B.子类只能继承父类的方法,不能继承父类的属性    

C.子类只能继承父类的非私有属性,不能继承父类的方法    

D.子类不能继承父类的私有属性

5. 关于Java中异常的叙述正确的是:(    )。   

A.异常是程序编写过程中代码的语法错误 

B.异常是程序编写过程中代码的逻辑错误    

C.异常出现后程序的运行马上中止    

D.异常是可以捕获和处理的

6. 设有定义 int i=123; long j=456; 下面赋值不正确的语句是(   )。   

A.j=i;   B.j=(long)i;    C.i=(int)j;     D.i=j; 

7. 要从文件“file.dat”文件中读出第10个字节到变量c中,下列哪个方法适合(  )。

A.  FileInputStream in=new  FileInputStream(“file.dat”);

in.skip(9);

int c=in.read();

B.  FileInputStream in=new  FileInputStream(“file.dat”);

in.skip(10);

int c=in.read();

C.  FileInputStream in=new FileInputStream(“file.dat”);

int c=in.read();

D.  RandomAccessFile in=new RandomAccessFile(“file.dat”);

    in.skip(9);

int c=in.readByte();

8. 定义类头时能使用的修饰符是(    )。  

   A.private   B.static      C.abstract    D.protected

9. 为AB类的一个无形式参数无返回值的方法method书写方法头,使得使用类名AB作为前缀就可以调用它,该方法头的形式为(      )。 

 A.static  void  method( )  

B.public  void  method( )                     

  C.final  void  method( )

D.abstract  void  method( ) 

10.下列关于Java线程的说法哪些是正确的(     )。

   A.每一个Java线程可以看成由代码、一个真实的CPU以及数据三部分组成。

   B.创建线程的两种方法中,从Tread类中继承的创建方式可以防止出现多父类问题。

   C.Tread类属于java.util程序包。

   D.以上说法无一正确。

三、程序填空题(本大题共10个空,每空2分,总计20分)

1.

abstract class Employee{

   public abstract double earnings( );

}

class YearWorker extends Employee{

public double earnings() {

return 300;

}

}

class MonthWorker extends Employee{

public double earnings() {

return 12*10;

}

}

class WeekWorker extends Employee{

public double earnings() {

return 52*2;

}

}

class Company

{

   Employee[] employee;

   double salaries=0;

   Company(Employee[ ] employee){

      this.employee=employee;

   }

   public double salariesPay()//计算公司年工资总额

   {

      salaries=0;

      for(int i=0;i<employee.length;i++)

               (1)        

      return salaries;

   }    

}

public class HardWork

{

   public static void main(String args[ ])

   {

   /*

    * 假定公司有20名员工,存储在数组employee中,

    * 其中0、3、6、9、12、15、18为WeekWorker,

    * 1、4、7、10、13、16、19为MonthWorker

    * 2、5、8、11、14、17为YearWorker

    */

      Employee[ ] employee=new Employee[20];

      for(int i=0;i<employee.length;i++)

       {

           if(i%3==0)

                     (2)         

           else if(i%3==1)

                     (3)         

           else if(i%3==2)

                     (4)         

       }      

                    (5)                  

     System.out.println("公司年工资总额:"+company.salariesPay( ) );

   }

}

 

2.

//把几个JAVA类型的数据写到一个文件,并读取出来。

import java.io.*;

public class DataInAndOutStream{

 public static void main(String args[]){

   try{  FileOutputStream fos=new FileOutputStream("DataOut.dat");

                                 (6)                                 

          out_data.writeInt(156);

          out_data.writeLong(987654L);  

          out_data.writeFloat(3.14f);

          out_data.writeDouble(92521.14);

          out_data.writeBoolean(true);

          out_data.writeUTF("JAVA语言真奇妙!");

          out_data.writeByte(123);

          out_data.writeChars("I am ok");   

        }

        catch(IOException e){}

        try{                     (7)                          

             DataInputStream in_data=new DataInputStream(fis);

                                  (8)                          

              //读取long整数

             System.out.println(":"+in_data.readLong());

              //读取第1个float数

             System.out.println(":"+in_data.readFloat());

              //读取第1个double数

             System.out.println(":"+_       (9)           );

              //读取第1个boolean值

             System.out.println(":"+in_data.readBoolean());

              //读取第1个UTF值

             System.out.println(":"+in_data.readUTF());

             //读取第1个Byte数

             System.out.println(":"+in_data.readByte());

               char c;

             while(       (10)       _)   //'\0'表示空字符

               System.out.print(c);

        }

        catch(IOException e){}

    }

}

四、写出下列各程序段的运行结果(本大题4小题,每小题5分,总计20分)

1.

public class Test{

public static void main(String[]args){

int x;

int a[]={0,0,0,0,0,0};

calculate(a,a[5]);

System.out.println("the value of a[0] is "+a[0]);

System.out.println("the value is a[5] is "+a[5]);}

static int calculate(int x[],int y){

for(int i=1;i<x.length;i++)

if(y<x.length) x[i]=x[i-1]+1;

return x[0];}

}

2. 

class A {      

double f(double x, double y) 

{        return x * y; 

     } 

    } 

   class B extends A { 

    double f(double x, double y) {      

 return x + y; 

    }    } 

   public class Test { 

    public static void main(String args[]) {      

 B obj = new B(); 

        System.out.println("The program output is " + obj.f(4, 6));     }   

 }

3.

public class Unchecked {  

public static void main(String[] args) {    

try {     method(); 

    } catch (Exception e) {     

System.out.println("A");    } 

finally {     System.out.println("B");    } 

  } 

  static void method() {    

try {     wrench(); 

System.out.println("C");

} catch (ArithmeticException e) {     

System.out.println("D");    } 

finally { 

 System.out.println("E");    } 

 System.out.println("F");   } 

 static void wrench() { 

 throw new NullPointerException(); 

 }

 } 

4.

class father{

  void speak(){

    System.out.println("I am father!");

  }

}

public class son extends father{

  void speak(){

    super.speak();

    System.out.println("I am son!");

  }

  public static void main(String args[]){

    son cxz=new son();

    cxz.speak();

  }

}

五、程序设计(本大题3小题,第一题10分,第二题12分,第三题8分,总计30分)

1. 编写一个Java程序实现三条线程,在线程中输出线程的名字,隔300毫秒输出一次,共输出20次。(10分)

2. 编写一个Java应用程序,从键盘读取用户输入两个字符串,并重载3个函数分别实现这两个字符串的拼接、整数相加和浮点数相加。要进行异常处理,对输入的不符合要求的字符串提示给用户,不能使程序崩溃。(12分)

3. 打印出所有的 "水仙花数 ",所谓 "水仙花数 "是指一个三位数,其各位数字立方和等于该数本身。例如:153是一个 "水仙花数 ",因为153=1的三次方+5的三次方+3的三次方。(8分)

 

答案:

考试科目面向对象程序设计Java考试时间100分钟  试卷总分100

考试班级:软件14-1~10班

一、判断题(本大题共20小题,每小题1分,总计20分)

×××√√      ××√×√     ×√√√√       √√××√

二、单项选择题(本大题共10小题,每小题2分,总计10分)

1.C  2.A  3.C  4.D   5.D   6.D   7.A   8.C   9.A   10.D

 

三、程序填空题(本大题共10小题,每题2分,总计20分)

1、salaries=salaries+employee[i].earnings();

2、employee[i]=new WeekWorker();

3、employee[i]=new MonthWorker();

4、employee[i]=new YearWorker();

5、Company company=new Company(employee);

6、DataOutputStream out_data=new DataOutputStream(fos);

7、FileInputStream fis=new FileInputStream("DataOut.dat");

8、in_data.skipBytes(4);

9、in_data.readDouble()

10、(c=in_data.readChar())!='\0'

四、写出下列各程序段的运行结果(本大题4小题,每小题5分,总计20分)

1、the value of a[0]is0

the value is a[5]is5

2、The program output is 10.0

3、E 

B

4、I am father!

I am son!

 

五、程序设计(本大题2小题,其中1题 10分,2题20分,总计30分)

1. 

class ThreadDemo extends Thread {

  public ThreadDemo(String str) {

super(str);

}

  public void run() {

    for(int i=0;i<20;i++){

System.out.print(“  ”+this.getName());

Try {

 Sleep(300);

}catch(InterruptedException e){

 System.out.println(e.getMessage());

 Return;

}

}

System.out.println(“  /end”);

}

}

public class TestThread {

 public static void main( String args[] ) {

   ThreadDemo thread1=new ThreadDemo(“T1”);

   ThreadDemo thread2=new ThreadDemo(“T2”);

   ThreadDemo thread3=new ThreadDemo(“T3”);

   thread1.start();

   thread2.start();

   thread3.start();

 }

}

 

2. 

import java.io.*;

public class Strinput 

{

  public static void main(String args[]) {

       String s1,s2,ss,si,sf;

       int i1,i2;

       float f1,f2;

       BufferedReader strin=new  BufferedReader(new InputStreamReader(System.in));

       try{System.out.print ("输入第一个字符串:" );

           s1= strin.readLine();

           System.out.print ("输入第二个字符串:" );

           s2= strin.readLine();}

       catch(Exception e){ System.out.println(e.getMessage());}

       i1 = Integer.parseInt(s1);

       i2 = Integer.parseInt(s2);

       f1 = Float.parseFloat(s1);

       f2 = Float.parseFloat(s2);

       ss = strAdd(s1,s2);

       si = strAdd(i1,i2);

       sf = strAdd(f1,f2);

       System.out.println ("输入的二个字符串相加结果为:"+ss );

       System.out.println ("输入字符串转换为整数相加结果为:"+si );

       System.out.println ("输入字符串转换为浮点数相加结果为:"+sf );

    }

   String strAdd(String str1,String str2) {

return str1+str2;

}

String strAdd(int int1,int int2) {

return  String.valueOf(int1+int2);

}

String strAdd(float flt1,float flt2) {

return  String.valueOf (flt1+flt2);

}

 }

 

3.

public class lianxi03 {
public static void main(String[] args) {
     int b1, b2, b3;
     for(int m=101; m<1000; m++) {
      b3 = m / 100;
      b2 = m % 100 / 10;
      b1 = m %    10;
      if((b3*b3*b3 + b2*b2*b2 + b1*b1*b1) == m) {
      System.out.println(m+"是一个水仙花数"); }
     }
}

猜你喜欢

转载自blog.csdn.net/nanaz11/article/details/81134061