Chinaunix首页 | 论坛 | 博客
  • 博客访问: 170041
  • 博文数量: 77
  • 博客积分: 1400
  • 博客等级: 上尉
  • 技术积分: 990
  • 用 户 组: 普通用户
  • 注册时间: 2009-06-21 18:13
文章分类

全部博文(77)

文章存档

2011年(1)

2009年(76)

我的朋友

分类: Java

2009-07-09 23:56:36

JAVA语言笔试题目

一、单选择题(每小题2分,共10)

1、编译Java  Application 源程序文件将产生相应的字节码文件,这些字节码文件的扩展名为(    B  )

    A.  .java     B.    .class

    C..html       D.    .exe

2 main方法是Java  Application程序执行的入口点,关于main方法的方法头以下哪项是合法的( B   

Apublic  static  void  main

Bpublic static  void main String  args[]

Cpublic static int  mainString  [] arg

Dpublic  void  mainString  arg[]

3、设 x = 1 , y = 2 , z = 3,则表达式  y+z--/++x  的值是(  A    )

    A.    3                       B.    3. 5

    C.    4                       D.    5

4、在Java  Applet程序用户自定义的Applet子类中,一般需要重载父类的(  D   )方法来完成一些画图操作。

    A.   start( )                    B.   stop( )

    C.   init( )                     D.   paint( )

5、不允许作为类及类成员的访问控制符的是(  C   )

    A.   public                    B.   private

    C.   static                     D.   protected

二、填空题(每空格1分,共20分)

1、开发与运行Java程序需要经过的三个主要步骤为      编辑                    

        编译                             运行                                 

2、如果一个Java  Applet源程序文件只定义有一个类,该类的类名为MyApplet,则类MyApplet必须是                           Applet          的子类并且存储该源程序文件的文件名为         MyApplet.java                         

3、如果一个Java  Applet程序文件中定义有3个类,则使用Sun公司的JDK编译器      javac        编译该源程序文件将产生          3            个文件名与类名相同而扩展名为      .class              的字节码文件。

4、在Java的基本数据类型中,char型采用Unicode编码方案,每个Unicode码占用     2           字节内存空间,这样,无论是中文字符还是英文字符,都是占用         2      字节内存空间。

        

 

BufferedReader br=new BufferedReader(

               new InputStreamReader(System.in));

            a[i] = Integer.parseInt(br.readLine( )); 

        } catch ( IOException  e ) { } ;

        for  ( i = n - 1 ; i >= 0 ; i -- )

            System.out.print(a[i]+"  ");

        System.out.println( );

    }

}

1

2

3

4

5

6

7

8

9

10

10  9  8  7  6  5  4  3  2  1 

3.

public abstract class ABC{

    long aver=0;

       long max=0;

       long min=0;

       int testSum=0;

 

       protected abstract  actionPerformed();

       public void  ABC (int testSum) {

          long start;

          long interval;

          long sum=0;

          this.testSum   = testSum;

          for (int i=0;i

              start=(new java.util.Date()).getTime();

             actionPerformed();

             interval=(new java.util.Date()).getTime()-start;

             sum+=interval;

             if (interval>max) max=interval;

             if (i==0) min=interval;

             else  if (interval

           }

           aver=sum/testSum;

           System.out.println("aver:\t"+aver+" miliSeconds");

           System.out.println("max:\t"+max+" miliSeconds");

           System.out.println("min:\t"+min+" miliSeconds");

       }

}

四、写出下面程序的运行结果(每小题14分,共28)

1

import    java.io.*;

5、设 x = 2 ,则表达式 ( x + + )3 的值是            1     

6、若x = 5y = 10,则x < yx >= y的逻辑值分别为      true        false       

7       抽象        方法是一种仅有方法头,没有具体方法体和操作实现的方法,该方法必须在抽象类之中定义。     final      方法是不能被当前类的子类重新定义的方法。

8、创建一个名为MyPackage 的包的语句是 package MyPackage                ,该语句应该放在程序的位置为:     第一行                        

9、设有数组定义:int   MyIntArray[ ] = { 10 , 20 , 30 , 40 , 50 , 60 , 70};   则执行以下几个语句后的输出结果是     0                

    int  s = 0 ;

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

         if  ( i % 2 = = 1 )  s += MyIntArray[i] ;

    System.out.println( s );

10、在Java程序中,通过类的定义只能实现          重继承,但通过接口的定义可以实现        重继承关系。

三、写出下列程序完成的功能。(每小题14分,共42)

 

1

public  class   Sum{ 

  public  static  void   main( String  args[ ]) {  

       double   sum = 0.0 ;

       for  ( int  i = 1 ;  i <= 100 ; i + + )

           sum += 1.0/(double) i ;

       System.out.println( "sum="+sum );

   }

}

sum=5.187377517639621

2

import  java.io.* ;

public  class  Reverse{  

  public static  void  main(String  args[ ]) {  

        int   i , n =10 ;

        int  a[ ] = new int[10];

        for  ( i = 0 ; i < n ; i ++ )

        try {

 

public  class  abc{        

    public  static  void main(String args[ ]) {  

        String str1=" Hello!" ;

        String str2=" I love JAVA." ;

        System.out.println(new  AB(str1,str2));

        System.out.println(str2);

    }

}

class   AB {

    String   s1;

    String   s2;

    AB( String  str1 , String  str2 ){ 

        s1 = str1; 

        s2 = str2;

str2+=str1;

    }

    public   String   toString( ) {  

        return  s1+s2;

    }

}

2

class Ex{

    public static void main(String[] args) {

           Fx f=new Fx(5);

    }

    Ex() {

           System.out.println("Ex,no-args");

    }

   

    Ex(int i) {

              System.out.println("Ex,int");

    }

}

class Fx extends Ex{

       Fx() {

              super();

              System.out.println("Fx,no-args");

    }

    Fx(int i) {

              this();

              System.out.println("Fx,int");

    }

}

 

 

阅读(801) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~