Java基础练习题 考试题 笔试题 面试题

一、简单Java程序调试

1)以下哪个是Java应用程序main方法的有效定义?

A. public static void main();

B. public static void main( String args );

C. public static void main( String args[] );

D. public static void main( Graphics g );

E. public static boolean main( String a[] );

2) 编译和运行以下代码的结果为:

public class MyMain{

public static void main(String argv){

    System.out.println("Hello cruel world");

 }

}

A.编译错误;

B.运行输出 "Hello cruel world"

C.编译无错,但运行时指示没有定义构造方法。

D.编译无错,但运行时指示没有正确定义main方法。

3 下列选项中不属于Java虚拟机的执行特点的一项是:

A.异常处理   B.多线程   C.动态链接   D.简单易学

4 不属于Java语言特点的一项是:

A.分布式  B. 安全性   C. 编译执行    D.面向对象

5 以下程序的运行结果为:

   public class Test{

public static void main(String argv[ ]){

    System.out.println("x="+5);

}

}

A. 5    B. x=5    C. "x="+5    D. "x="5

6) 以下程序的运行结果为:

   public class Test{

public static void main(String argv[ ]){

    System.out.println("good"+"morning");

}

}

A. goodmorning     B. "good"+"morning"     

C. good morning    D. good+morning

二、Java符号与表达式

1) 现有一个int类型的整数和一个double类型的数进行加法运算,则得到的结果类型为:

    Aint类型   B. double类型   C. float类型   D. long类型

2)下面程序段的输出结果是:

  int  a = 2;

  System.out.print( a++);

  System.out.print( a);

  System.out.print(++a);

  A333      B334    C234   D233

3) 以下代码的输出结果?

public class Test{

  int x=3;

  public static void main(String argv[]){

     int x= 012;

     System.out.println(x);

  }

}

A12       B012    C10       D3 

4) 下列定义语句正确的是:

Achar c="/n";   Bint i=12;   Cfloat f=2.8;   Dboolean b=null;

5)检查如下代码:

 public class Quiz2_l{

  public static void main(String[] args)  {

    int a = 8;

    int b = -8;

    System.out.print(a<<2);

    System.out.print("" + (b>>1) );

   }

 }

 下列哪条语句正确描述了程序在编译和运行时的行为?

A.编译成功,输出为“32,-4

B. 编译成功,输出为“16,4

C. 编译成功,输出为“32,2147483644

D. 编译成功,输出为“16,2147483644

E. 编泽器拒绝表达式 b>>,因为不能对一个负数应用>>操作符

6)以下代码中变量result的可能类型有哪些?

  byte  b = 11;

  short  s = 13;

  result = b * ++s;

Abyte, short, int, long, float, double

Bboolean, byte, short, char, int, long, float, double

Cbyte, short, char, int, long, float, double

Dbyte, short, char

Eint, long, float, double

7)以下代码的输出结果为:

  System.out.println(" " +2 + 3);

  System.out.println(2 + 3);

  System.out.println(2 + 3 +"");

  System.out.println(2 + "" +3);    

A.第3行出现编译错误

B.输出23, 5, 5 23.

C.输出5, 5, 5 23.

D.输出 23, 5, 23 23.

8)设有如下变量说明:

byte myByte;

int myInt;

long myLong;

char myChar;

float myFloat;

double myDouble;

以下赋值语句哪个需要强制转换。

AmyInt = myByte;

BmyInt = myLong;

CmyByte = 3;

DmyInt = myChar;

EmyFloat = myDouble;

FmyFloat = 3;

GmyDouble = 3.0;

9)考虑如下两语句:

  1. boolean passingScore = false && grade == 70;

  2. boolean passingScore = false & grade == 70;

表达式grade == 70 在什么地方被计算

A.在 1 2中均计算

B.在 1 2中均未计算

C.在1中计算,在2中未计算

D.在2中计算,在1中未计算

E.非法,因为 false 应写 FALSE

10)设有一个整数x 其二进制值为10011100 (1 字节表示),则执行如下语句后 z的二进制值为:

int y = 1 << 7;

int z = x & y;

A10000001   B10000000  C00000001

D10011101   E10011100

11) 以下哪些编译正确?

Ashort myshort = 99S;

BString name = 'Excellent tutorial Mr Green';

Cchar c = 17c;

Dint z = 015;

12) 以下哪些是java关键字?

Adouble  BSwitch  Cthen  Dinstanceof

13) 以下程序行的输出结果为?

System.out.println(010|4);

A14    B0    C6    D12

14) 设有如下变量

char c = 'c';

int i = 10;

double d = 10;

long l = 1;

String s = "Hello";

以下哪些语句编译不出错?

Ac=c+i;     B s+=i;     C i+=s;    D c+=s;

15) 整型变量a,b的值定义如下:

  int a=3;

  int b=4;

则表达式 ++a==b的值为:

A4    Bfalse   C3    Dtrue

16) 执行下列代码后输出结果为:

public class test {

    public static void main(String  args[]) {

        int a=2;

        int b=3;

        int c=7;

        int d=a>c?a:c;

        d=d>>2>b? d:b;

        System.out.println(b);

    }

  }

A2     B3    C5    D7

三、分支程序设计

1)下列语句片段的结果为

int result;

int a=17,b=6;

result=(a%b>4)? a%b:a/b ;

System.out.println(result); 

A. 0    B. 1      C. 2    D. 5

2)以下程序的运行结果为:

    1. public class Conditional {

    2.    public static void main(String args [] )  {

    3.      int x = 4;

    4.      System.out.println( "value is " +((x >4) ? 99.99 : 9));

    5.    }

    6.  }

   A. 输出:value is 99.99

   B. 输出: value is 9

   C. 输出: value is 9.0

   D. 在第4行出现编译错误

3)以下代码段的输出结果为

1. int x = 0, y = 4, z = 5;

2. if (x > 2)  {

3.   if (y < 5) {

4.      System. out .println ( "message one" );

5.    }

6.   else {

7.      System.out.println( "message two");

8.   }

9.  }

10. else if (z > 5)  {

11.    System.out.println("message three");

12. }

13. else {

14.    System.out.println( "message four");

15. }

A. message one

B. message two

C. message three

D. message four

4 以下程序的输出结果为:

public class test {

  public static void main(String args[]) {

   int x=1,y=1,z=1;

   if  (x--==1&&y++==1||z++==1)

      System.out.println("x="+x+",y="+y+",z="+z);

   }

}

A x=0,y=2,z=1

B x=1,y=2,z=1

C x=0,y=1,z=1

D x=0,y=2,z=2

5 编译和运行以下代码结果为:

1. public class EqualsTest{

2.   public static void main(String args[]){

3.     byte A=(byte)4096;

4.     if(A==4096) System.out.println("Equal");

5.     else System.out.println("Not Equal");

6.   }

7. }

A.在第3行出现转换丢失精度的编译错误.

B.输出 "Not Equal".

C.输出 "Equal".

6 关于以下程序哪条叙述正确?

1. int  j = 2;

2. switch ( j ) {

3.    case 2:

4.      System.out.println ("value is two");

5.    case 2 + 1:

6.      System.out.println ("value is three");

7.      break;

8.    default:

9.      System.out.println("value is " + j);

10.      break;

11. }

A. 5行的表达式不合法;

B. 变量j是可接受的,switch中表达式可以是byte, short, int,long的任何类型;

C. 输出为value is two

D. 输出是value is two 后跟value is three

E. 输出是value is two 后跟 value is 2

7)以下程序的编译运行结果为:

1:    public class Q10

2:    {

3:      public static void main(String[] args)

4:      {

5:          int i = 10;

6:          int j = 10;

7:          boolean b = false;

8:         

9:          if( b = i == j)

10:            System.out.println("True");

11:         else

12:            System.out.println("False");

13:       }

14:    }

A. 9行出现编译错误;

B. 9行出现运行错误;

C. 输出 True

D. 输出 False

8)以下程序的编译和运行结果为?

class test {

   static boolean check;

   public static void main(String args[]) {

       int i;

       if(check == true)

         i=1;

       else

         i=2;

       if(i=2) i=i+2;

       else i = i + 4;

       System.out.println(i);

    }

}

A. 3    B. 4    C. 5    D. 6    E. 语句if(i=2)编译出错

9) 以下代码:

if (a >4)

System.out.println("test1");

else if (a >9)

System.out.println("test2");

else

System.out.println("test3");                    

a为何值将有输出结果test2

A.  小于 0

B.  小于 4

C.  4 9之间

D.  大于9

E.  无任何可能

10)有如下代码段:

switch ( x ){

     case 1:System.out.println("One");break;

    case 2:

    case 3:System.out.println("Two");break;

    default:System.out.println("end");

}

变量x的取值下列哪些情形时,能使程序输出"Two"

A. 1   B. 2    C. 3   D. default

11)以下程序的输出结果为

  public class test {

     public  static void main(String agrs[]) {

       char c1=’B’,c2=’C’;

       if (c1+1<c2) ++c1;

       System.out.println(c1);

     }

  }

  A. B    B. b    C. C     D. c

12) 假设aint类型变量,并初始化为1,则下列哪个为合法的条件语句?

  A.  if (a) {  }       B.  if (a<<3)  {  }

  C.  if (a=2) {   }    D.  if (true)  {   }

四、循环程序设计

1)执行以下程序后,输出结果为

public class ex2{

 public static void main(String args[]) {

    int f=1;

    int k;

    for (k=2;k<5;k++)

       f*=k;;

    System.out.println(k);  

 }

}

A. 0     B. 1      C. 5     D. 4     E. 24

2 设有如下类

class Loop{

  public static void main(String[] agrs) {

    int x=0;int y=0;

    outer:

       for(x=0;x<100;x++){

    middle:

        for(y=0;y<100;y++){

          System.out.println("x="+x+"; y="+y);

          if(y==10){ <<<insert code>>> }

        }

      }

  }

}

<<<insert code>>>处插入什么代码可以结束外循环?

Acontinue middle;

Bbreak outer;

Cbreak middle;

Dcontinue outer;

Enone of these

3)以下代码的运行结果为:

public class Calc {

  public static void main (String args []) {

     int total = 0;

     for (int i = 0, j = 10; total > 30; ++i, --j) {

         System.out.println(" i = " + i + " : j = " + j);

         total += (i + j);

     }

     System.out.println("Total " + total);

  }

}

A. 产生运行错误

B. 产生编译错误

C. 输出 "Total 0"

D. 产生如下输出:

   i = 0 : j = 10

   i = 1 : j = 9

   i = 2 : j = 8

   Total 30

4)以下程序的运行结果为:

public class test {

   public static void main(String args[]) {

      int i=0, j=2;

      do {

         i=++i;

         j--;

      } while(j>0);

      System.out.println(i);

   }

}

A. 0    B. 1    C. 2  D.3

5)以下程序的运行结果为?

class xyz {

  public static void main(String args[]) {

     int i,j,k;

     for (i = 0; i < 3; i++) {

         for(j=1; j < 4; j++) {

             for(k=2; k<5; k++) {

                 if((i == j)   && (j==k))

                     System.out.println(i);

             }               

          }

     }

   }

}

A. 0    B. 1     C. 2    D. 3    E. 4

6 以下程序的运行结果为?

class test {

   public static void main(String args[]) {

     int i,j=0;

     for(i=10;i<0;i--) { j++; }

     switch(j) {

      case (0) :  j=j+1;

      case (1) :  j=j+2;  break;

      case (2) :  j=j+3;  break;

      case (10) : j=j+10; break;

      default  :   break;

     }

    System.out.println(j);

  }

}

A. 0     B. 1    C. 2    D. 3    E. 10

7 观察以下程序段:

int i=1,j=10;

do{

     if(i++>--j) continue;

} while(i<5);

执行完后,ij的值分别为:

A i=6  j=5        B i=5  j=5

C i=6  j=4        D i=5  j=6

8)以下程序的输出结果为:

  public class example {

   public static void main(String args[]) {

     int s=0;

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

       for (int j=10;j>3*i;j--)

          s += i*j;

     }

     System.out.println(s);

   }

}

  A. 127      B.136      C. 147      D.153

9) 以下程序的输出结果为:

  public class example {

     public static void main(String args[]) {

        int i=0;

        for (i=0;i<4;i++) {

           if (i==3) 

              break;

           System.out.print(i);

        }

        System.out.println(i);

     }

 }

  A.0123    B.0122    C.123    D.234

10) 以下程序的运行结果为

  class Prob10 {  

      static boolean b1;

      public static void main(String [] args) {

         int i1 = 11;    

         double f1=1.3;

         do {

            b1 = (f1 > 4) && (i1-- < 10);

            f1 += 1.0;

         } while (!b1);

         System.out.println(b1 + "," + i1 + "," + f1);

      }

   }

A. false,9,4.3      B. true,11,1.3   

C. false,8,1.3      D. true,8,7.3

五、方法设计

1)以下代码的输出结果?

public class Test{

  static int x=5;

  public static void main(String argv[]){

     change(x);

     x++;

     System.out.println(x);

  }

   static void change(int m){

     m+=2;

  }

}

A. 7      B. 6    C. 5      D. 8 

2) 以下代码的输出结果?

public class Test{

  int x=5;

  public static void main(String argv[]){

      Test t=new Test();

      t.x++;

      change(t); 

      System.out.println(t.x);

  }

   static void change(Test m){

      m.x+=2;

  }

}

A. 7      B. 6    C. 5      D. 8 

3)       以下代码的输出结果?

public class Test{

  public static void main(String argv[]){

      String x="hello";

      change(x); 

      System.out.println(x);

  }

  static void change(String m){

      m=m+2;

  }

}

A. hello      B. hello2

C. 编译报错   D. 运行报错,不能将串与整数相加

4)设有如下类:

class MyPoint {

 void myMethod() {

    int x, y;

      x = 5; y = 3;

      System.out.print( " ( " + x + ", " + y + " ) " );

      switchCoords( x, y );

      System.out.print( " ( " + x + ", " + y + " ) " );

   }

   void switchCoords( int x, int y ) {

      int temp;

      temp = x;

      x = y;

      y = temp;

      System.out.print( " ( " + x + ", " + y + " ) " );

   }

}

如果执行myMethod()方法,则输出结果为?

A. (5, 3) (5, 3) (5, 3)

B. (5, 3) (3, 5) (3, 5)

C. (5, 3) (3, 5) (5, 3)

5)以下程序的输出结果为:

public class test {

   public static void main(String args[]) {

     int s=0;

     for (int k=0;k<=10;k++)

        s+=method(2,k)-1;

     System.out.println(s);

   }

   public static int method(int n,int m) {

      if (m==0)

         return 1;

      else

        return n*method(n,m-1);

   }

}

A. 2048   B. 1024    C. 2036    D.2000

6) 以下程序的输出结果为:

public class test {

   public static void main(String args[]) {

     int m=0;

     for ( int k=0;k<2;k++)

        method(m++);

     System.out.println(m);

   }

   public static void method(int m) {

       System.out.print(m);

   }

}

  A. 000     B. 012    C.123    D.111

 

六、数组的使用

1)输入如下命令运行Java应用程序。

   java MyTest  "1  2  3"

则命令行参数数组args中得到的值哪个正确?

A. args[0] = "MyTest 1 2 3"

B. args[0] = "1  2  3"

C. args[0] = "1"

D. args[1]= "1  2  3"

2) 在注释//Start For loop 处要插入哪段代码可实现根据变量i的值定位数组ia[]的元素?

public class Lin{

  public void amethod(){

      int ia[] = new int[4];

       //Start For loop       

       {

         ia[i]=i;

         System.out.println(ia[i]);

        }

     }

  }

A. for (int i=0; i < ia.length() -1; i++)

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

C. for (int i=1; i < 4; i++)

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

3)以下代码的调试结果?

public class Q {

  public static void main(String argv[]) {

    int anar[]= new int[5];

    System.out.println(anar[0]);

  }

}

A. 编译错误:anar 在引用前未初始化。

B. null

C. 0

D. 5

4) 下列创建二维整型数组正确语句是:

A.  int a[][] = new int [10,10];

B.  int a[10][10] = new int [][];

C.  int a[][] = new int [10][10];

D.  int []a[] = new int [10][10];

5) 给出下面代码:

public class Person{

  static int arr[] = new int[10];

  public static void main(String a[]) {

   System.out.println(arr[1]);

  }

}

以下那个说法正确?

A. 编译时将产生错误;

B. 编译时正确,运行时将产生错误;

C. 输出0

D. 输出null

6)设有如下说明:

char[] c = new char[100];

则,c[50]的值为?

A. 50

B. '/u0000'

C. " "

D. 不定

E. null,直到被赋值。

7 设有如下程序,其调试结果为:

class Q2 {

      public static void main(String[] args) {

        int[] seeds = {1,2,3,4,6,8};

        int n= seeds.length;

        for (int i = 0; i < 3; i++)

          for (int k = 0; k< n-1; k++)

            seeds[k]= seeds[k+1];

        for (int i = 0; i <n-1; i++)

           System.out.print("/t"+seeds[i]);

       }

}

A.输出: 1     2     3     4    6

B.输出: 4     6     8     8    8  

C.输出: 2     3     4     6    8  

D.输出: 2     3     4     6   

七、类与对象编程

1) 以下程序的运行结果为:

public class My{

   int value;

   public static void main(String args[]) {

       My x=new My();

       if (x==null)

           System.out.println("No Object");

        else

           System.out.println(x.value);    

     }

}

A. 0     B. 1      C. No Object     D. 编译错误    E. null

2)以下程序的运行结果为:

public class A {

  static int k=3;

  public static void main(String[] args) {

    int k=4;

    A  x1=new A();

    x1.k++;

    A  x2=new A();

    x2.k++;

    k++;

    System.out.println(x1.k);

  }

}

A. 3     B. 4     C.5      D.6     E.7

3 编译和运行以下程序结果为:

public class A {

  static int k=3;

  static int m;

  public static void main(String[] args) {

     k++;

     if (m==0)

       System.out.println(k);

     else

       System.out.println(B.k);

     k++;

  }

 }

 class B {

     static int k=6;

 }

A. 3     B. 4     C.5      D.编译错误     E.6

4)编译和运行以下程序结果为:

    1:  public class Q21  {

    2:      int maxElements;

    3:      void Q21()  {

    4:          maxElements = 100;

    5:          System.out.println(maxElements);

    6:      }

    7:     Q21(int i)  {

    8:          maxElements = i;

    9:          System.out.println(maxElements);

    10:     }

    11:     public static void main(String[] args) {

    12:          Q21 a = new Q21();

    13:          Q21 b = new Q21(999);

    14:      }

    15:  }

    A. 输出100 999.

    B. 输出999 100.

    C. 2行出现编译错误,变量 maxElements未初始化.

D. 12行出现编译错误.

5)以下的程序的调试结果为

public class Scope{

   int i;

   public static void main(String argv[]){

      Scope s = new Scope();

      s.amethod();

   }

   public static void amethod(){

     System.out.println(i);

   }

 }

A. 输出结果为:0

B. 无输出

C. 编译错误

D. 输出null

6)给出下面代码:

public class Person{

  static int arr[] = new int[10];

  public static void main(String a[]) {

   System.out.println(arr[1]);

  }

}

以下那个说法正确?

A. 编译时将产生错误;

B. 编译时正确,运行时将产生错误;

C. 输出0

D. 输出null

7)以下的程序的调试结果为?

public class As{

    int i = 10;

    int j;

    char z= 1;

    boolean b;

    public static void main(String argv[]){

        As a = new As();

        a.amethod();

    }

    public void amethod(){

        System.out.println(j);

        System.out.println(b);               

    }

}

A.输出0 false

B. 输出0 true

C. 编译错误,b 未初始化

D. 编译错误, z 必须赋字符值

8)以下的程序的调试结果为?

public class MyAr{

    public static void main(String argv[]) {

        MyAr m = new MyAr();

        m.amethod();

    }

    public void amethod(){

        static int i;

        System.out.println(i);

    }

}

A. 输出结果为 0

B. 运行出错

C. 输出结果为 null

D. 编译错误

9)  以下程序的运行结果为?

class ValHold{

        public int i = 10;

}

public class ObParm{

    public static void main(String argv[]){

        ObParm o = new ObParm();

        o.amethod();

    }

    public void amethod(){

        int i = 99;

        ValHold v = new ValHold();

        v.i=30;

        another(v,i);

        System.out.print( v.i );

    }

    public void another(ValHold v, int i){

        i=0;

        v.i = 20;

        ValHold vh = new ValHold();

        v =  vh;

        System.out.print(v.i);

        System.out.print(i);

   }

}

A10030    B. 20030    C. 209930   D. 10020

八、继承与多态

1)以下程序调试结果为:

class Base{

   Base(){

      int  i = 100;    

      System.out.print (i);

   }

 }

 public class Pri extends Base{

    static int i = 200;

    public static void main(String argv[]){

         Pri p = new Pri();

         System.out.print(i);

    }

 }

 A.编译错误    B200   C100200    D100

2 以下程序调试结果为:

 public class Test {

    int m=5;

    public  void some(int x) {

        m=x;

    }

    public static void main(String args []) {

        new Demo().some(7);

    }

}

class Demo extends Test {

    int m=8;

    public  void some(int x) {

        super.some(x);

       System.out.println(m);

    }

}

A5    B8   C7   D.无任何输出  E.编译错误

3)  试完成下述程序片段:

public class Point()

{  int x,y;

    public  Point(int x,int y)

    {      =x;      =y;

     }

     ......

 }

A Point.x   Point.y     B.无解   C x1    y1   Dthis.x    this.y

4)考虑如下类:

1. class Test(int i) {

2.    void test(int i) {

3.       System.out.println("I am an int.");

4.     }

5.    void test(String s) {

6.       System.out.println("I am a string.");

7.    }

8.

9.    public static void main(String args[]) {

10.     Test t=new Test();

11.     char ch="y";

12.     t.test(ch);

13.   }

14. }

以下哪条为真?

A.行 5 不能通过编译,方法不能被覆盖.

B.行 12 不能通过编译, 因为没有一个test()方法含字符参数.

C.代码可以编译但在12行将出现异常.

D.代码可以编译且产生如下输出: I am an int.

E.代码可以编译且产生如下输出: I am a String.

(5) Test1定义如下:

1public  class  Test1{

2        public  float  aMethodfloat  afloat  b{   }

3       

4}

将以下哪种方法插入行3是不合法的。(          

Apublic  float  aMethodfloat  a float  bfloat  c{  }

Bpublic  float  aMethodfloat  cfloat d{  }

Cpublic  int  aMethodint  a int b{  }

Dprivate float  aMethodint aint bint c{  }

6)考虑如下代码:

class Tree{}

class Pine extends Tree{}

class Oak extends Tree{}

public class Forest {

public static void main( String[] args ) {

      Tree tree = new Pine();

      if( tree instanceof Pine )

          System.out.println( "Pine" );

      if( tree instanceof Tree )

          System.out.println( "Tree" );

      if( tree instanceof Oak )

       System.out.println( "Oak" );

      else

System.out.println( "Oops" );

   }

}

则输出结果中有哪些?

APine   BTree   CForest   DOops   E.无输出

7)以下程序的编译和运行结果为?

abstract class Base{

    abstract public void myfunc();

    public void another(){

        System.out.println("Another method");

    }

}

public class Abs extends Base{

    public static void main(String argv[]){

        Abs a = new Abs();

        a.amethod();

     }

    public void myfunc(){

         System.out.println("My Func");

     }

    public void amethod(){

        myfunc();     

     }

}

A.输出结果为 My Func

B.编译指示 Base 类中无抽象方法

C.编译通过,但运行时指示Base 类中无抽象方法

D.编译指示Base 类中的myfunc方法无方法体,没谁会喜欢该方法。

8) 以下程序的调试结果为?

class Base{

public final void amethod(){

        System.out.println("amethod");

        }

}

public class Fin extends Base{

   public static void main(String argv[]){

        Base b = new Base();

        b.amethod();

   }

}

A.编译指示带有final 方法的类自己必须定义为final

B.编译指示不能继承含有final 方法的类

C.运行错误,原因是Base类没有定义为final

D.运行输出 amethod

9) 在同一目录编译和运行以下两文件结果如何?

//文件 P1.java

package MyPackage;

class P1{

    void afancymethod(){

        System.out.println("What a fancy method");

    }

}

//文件 P2.java

public class P2 extends P1{

    public static void main(String argv[]){

        P2 p2 = new P2();

        p2.afancymethod();

    }

}

A.两个均通过编译,P2运行时输出 What a fancy method

B.没一个通过编译

C.两个均通过编译,但P2运行时出错

DP1 通过编译,但P2出现编译错误

10)以下程序的调试结果为?

public class Outer{

public String name = "Outer";

public static void main(String argv[]){

     Inner i = new Inner();

     i.showName();

}

private class Inner{

    String name =new String("Inner");

    void showName(){

          System.out.println(name);

    }

  }

}

A.输出结果 Outer

B.输出结果 Inner

C.编译错误,因Inner类定义为私有访问

D.在创建Inner类实例的行出现编译错误

11) 设有如下代码:

class Base{}

public class MyCast extends Base{

    static boolean b1=false;

    static int i = -1;

    static double d = 10.1;

    public static void main(String argv[]){

        MyCast m = new MyCast();

        Base b = new Base();

        //Here

    }

}

则在 //Here处插入哪个代码将不出现编译和运行错误。

Ab=m;   Bm=b;   Cd =i;   Db1 =i;

12)  设有如下代码:

interface IFace{}

class CFace implements IFace{}

class Base{}

public class ObRef extends Base{

    public static void main(String argv[]){

        ObRef obj = new ObRef();

        Base b = new Base();

        Object obj1 = new Object();

        IFace obj2 = new CFace();

//Here

    }

}

则在 //Here处插入哪个代码将不出现编译和运行错误。

Aobj1=obj2;   Bb=obj;   Cobj=b;  Dobj1=b;

13) 设有类定义如下:

class Base{

public Base(int i){}

}

public class MyOver extends Base{

public static void main(String arg[]){

     MyOver m = new MyOver(10);

}

MyOver(int i){

     super(i);

}

MyOver(String s, int i){

      this(i);

      //Here

}

}

以下哪条语句可以安排在//Here ?

AMyOver m = new MyOver();

Bsuper();

Cthis("Hello",10);

DBase b = new Base(10);

14) 设有类定义如下:

class InOut{

String s= new String("Between");

public void amethod(final int iArgs){

    int iam;

    class Bicycle{

        public void sayHello(){

            //Here

        }

     }

 }

 public void another(){

     int iOther;

 }

}

以下哪些语句可以安排在//Here ?

A. System.out.println(s);

BSystem.out.println(iOther);

C. System.out.println(iam);

D.     System.out.println(iArgs);

九、常用系统类

1) 关于以下程序段,正确的说法是

1  String  s1="Hello";

2  String  s2="Hello";

3  ifs1= =s2

4      System.out.println("s1= =s2");

5  if (s1.equals(s2))

6  System.out.println("s1.equals(s2) ");

A.  4与行6都将执行

B.  4执行,行6不执行

C.  6执行,行4不执行

D.  4、行6都不执行

2) 要产生[20999]之间的随机整数使用哪个表达式?

A(int)(20+Math.random()*979)

B. 20+(int)(Math.random()*980)

C. (int)Math.random()*999

D. 20+(int)Math.random()*980

3) 下列程序运行的结果为:

public class Example{

  String str=new String("good");

  char[] ch={'a','b','c'};

  public static void main(String args[]){

    Example ex=new Example();

    ex.change(ex.str,ex.ch);

    System.out.print(ex.str+" and ");

    Sytem.out.print(ex.ch);

  }

  public void change(String str,char ch[]){

    str="test ok";

    ch[0]='g';

  }

}

A.  good and abc

B.  good and gbc

C.  test ok and abc

D.  test ok and gbc

4) 设有如下程序

public class test {

   public static void main(String args[]) {

      Integer intObj=Integer.valueOf(args[args.length-1]);

      int i = intObj.intValue();

      if(args.length > 1)

         System.out.println(i);

      if(args.length > 0)

         System.out.println(i - 1);

      else

         System.out.println(i - 2);

   }

}

运行程序,输入如下命令:

   java test 2

则输出为:

A. test      B. test -1     C. 0

D. 1         E. 2

5) 下列程序运行的结果为:

public class test {

  public static void main(String args[]) {

    int i;

    float  f = 2.3f;

    double d = 2.7;

    i = ((int)Math.ceil(f)) * ((int)Math.round(d));

    System.out.println(i);

  }

}

A. 4       B. 5       C.  6

D. 6.1     E. 9

6)如果以下条件成立,则用到java.lang.Math 类中哪个方法?

method( -4.4 ) == -4;

A. round()    B. min()   C. trunc()    D. abs()

E. floor()    F. ceil()

7) set集合如何处理重复元素

A.如果加入一个重复元素将抛出异常

B.如果加入一个重复元素add方法将返回false

C. 集合通过调用equals方法可以返回包含重复值的元素。

D. 重复值将导致编译出错。

8) 以下哪个方法是Vector类中增加一个新元素的方法。

AaddElement    B. insert    C. append   D. addItem

9) 以下哪些方法是Collection 接口的方法?

A. iterator    B. isEmpty    C. toArray    D. setText

十、Applet编程

1)所有变量初始化、对象创建、参数设置等可以安排在Applet的什么方法内完成.     

Ainit      B. start    C. stop     D. 以上都不是

2)一个部件重绘时,方法调用按下面哪个次序?

A.直接调用 paint()

B.调用update ,而update会调用 paint()

C.调用repaint(),由它调用update(), update 再调用 paint()

D. 调用 repaint(),它将直接调用 paint

3 java.awt.Graphics 类的哪个方法可绘制填充矩形?

AfillRect()        BdrawRect()     CfillOval()

DdrawPolygon()     EdrawLine()

4 下列哪个方法不属于播放声音的方法?

A loop()   B. stop()   C. start()   D. play()

5)  Applet画面的左上角至右下角画一条直线,则//draw处应如何选择?

import java.awt.*;

import java.applet.*;

public class myApplet extends Applet {

 public void paint(Graphics g) {

    //draw

 }

}

A.     g.drawLine(0,0,getHeight(),getWidth());

B.     g.drawLine(0,getWidth(),0,getHeight());

C.     g.drawLine(0,getWidth(),getHeight(),0);

D.     g.drawLine(getWidth(),getHeight(),0,0);

6) 下列说法错误的一项是?

AgetDocumentBase()用于获取包含AppletHTML文件的URL

BgetCodeBase()用于获取Applet主类的URL

CgetParameterString name)用于获取<PARAM>标记中的参数值

D.若指定参数在HTML中没有说明,则Applet将停止运行。

7) 下列说法错误的一项是?

AgetImage()方法无论图像是否存在,都立即返回

BgetImage()方法调用图像的时候,一直等图像加载完毕才返回

C.使用getImage()方法时,只有图像真正需要绘制时,数据才真正加载。

D.由于网络带宽的限制,图像的显示过程可能会很慢。

8)在HTML文件中通过什么标记嵌入Applet

A. <APPLET>   B. <CODE>    C. <CODEBASE>   D. <PARAM>

十一、图形用户界面编程

1 一个部件在水平方向会改变大小,但垂直方向不变,则放到什么位置。

ABorderLayout 布局的North South位置

BFlowLayout 布局的第一个部件

CBorderLayout 布局的East West位置

DBorderLayout 布局的Center位置

EGridLayout布局中

2)以下AWT类中哪些实现部件的布局?

ALayoutManager

BGridBagLayout

CActionListener

DWindowAdapter

EFlowLayout

3 容器的add( Component comp ) add( String name, Component comp ) 方法在加入什么部件时将抛出IllegalArgumentException

AButton    BList    CWindow    DTextArea

E.包含这个容器的容器

4 设有以下程序:

import java.awt.*;

public class FlowAp extends Frame{

   public static void main(String argv[]){

      FlowAp fa=new FlowAp();

      fa.setSize(400,300);

      fa.setVisible(true);

  }

  FlowAp(){

     add(new Button("One"));

     add(new Button("Two"));

     add(new Button("Three"));

     add(new Button("Four"));

  }

}

以下哪个描绘了应用的外观?

A.窗体每边有4个标记为One Four的按钮

B.从顶到底有安排有4个标记为One Four的按钮

C.一个很大的标记为 Four的按钮在正中央

D.运行时指示没有设置布局管理器的错误

5)  如何设置当前的布局管理器

A.使用 setLayout 方法

B.一旦创建了部件,不能改变部件的布局管理器。

C.使用setLayoutManager 方法

D.使用updateLayout 方法

6)  以下代码运行后外观为?

import java.awt.*;

public class CompLay extends Frame{

   public static void main(String argv[]){

      CompLay cl = new CompLay();

   }

   CompLay(){

      Panel p = new Panel();

      p.setBackground(Color.pink);

      p.add(new Button("One"));

      p.add(new Button("Two"));

      p.add(new Button("Three"));

      add("South",p);

      setLayout(new FlowLayout());

      setSize(300,300);

      setVisible(true);

  }

}

A.按钮按从左向右的次序出现在窗体的底部

B.按钮按从左向右的次序出现在窗体的顶部

C.按钮将不显示

D.只有一个按钮显示占满整个窗体

7) 以下程序调试结果为

   //演示事件处理

import java.awt.*;

import java.awt.event.*;

public class MyWc extends Frame implements WindowListener{

   public static void main(String argv[]){

        MyWc mwc = new MyWc();

        }

    public void windowClosing(WindowEvent we){

             System.exit(0);

      }

    public void  MyWc(){

        setSize(300,300);

        setVisible(true);

    }

}

A.编译错误

B.创建的窗体会关闭掉

C.运行无输出

D.编译错误,import语句前不能有注释语句

8)  以下叙述正确的有?

A.如果一个部件注册多个监听者,事件只会被最后一个监听者处理。

B.如果一个部件注册多个监听者,事件将被所有监听者处理。

C.一个部件注册多个监听者将导致编译出错。

D.可以将一个部件已注册的监听者移去。

9)  以下哪个是正确的事件处理方法

AmousePressed(MouseEvent e){}

BMousePressed(MouseClick e){}

CfunctionKey(KeyPress k){}

DcomponentAdded(ContainerEvent e){}

10) 关于JDK 1.1的事件处理以下那条为真?

A.一个类可以实现多个监听者接口;

  B.如果一个类实现一个监听者接口,它只要覆盖其用到的方法;

  CMouseMotionAdapter类的所有方法返回类型均为void

11)  以下哪个是MenuItem类的方法?

AsetVisible( boolean b )

BsetEnabled( boolean b )

CgetSize()

DsetForeground( Color c )

EsetBackground( Color c )

12)以下类中,哪个类的子类不能直接创建实例?

APanel      BDialog      CContainer     DFrame

十二、异常处理

1)以下程序发生什么异常?

    class A {

        int x;

        public static void main {

           A  x;

           System.out.println(x.x);

        }

    }

A IOException

B.  InterruptException

C.  NullPointerException

D.  DataFormatException

2)设有如下方法:

public void test() {

       try {

 oneMethod();

            System.out.println("condition 1");

        } catch (ArrayIndexOutOfBoundsException e) {

            System.out.println("condition 2");

        } catch(Exception e) {

            System.out.println("condition 3");

       } finally {

            System.out.println("finally");

        }

    }

如果oneMethod正常运行,则输出结果中有哪些?

A. condition 1

B. condition 2

C. condition 3

D. finally

3 设有如下代码:

public void fun () {

    int i;

    try

    {

          i=System.in.read ();

          System.out.println("Location 1");

     } catch (IOException e) {

            System.out.println("Location 2");

     } finally {

           System.out.println("Location 3");

       }

       System.out.println("Location 4");

}

如果有一个IOException发生, 则输出有哪些?

A. Location 1

B. Location 2

C. Location 3

D. Location 4

4  设有如下代码:

1 String s = null;

    2 if ( s != null & s.length() > 0)

    3    System.out.println("s != null & s.length() > 0");

    4 if ( s != null && s.length() > 0)

    5    System.out.println("s != null & s.length() > 0");

     6 if ( s != null || s.length() > 0)

     7    System.out.println("s != null & s.length() > 0");

     8  if ( s != null | s.length() > 0)

9    System.out.println("s != null | s.length() > 0");

以下行中哪些会产生空指针异常。 

A. 2,4

B. 6,8

C. 2,4,6,8

D. 2,6,8

5 Test1Test2定义如下:

1public class  Test1 {

2   public  float  aMethodfloat afloat b throws IOException {

3   }

4 }

5 public  class  Test2  extends  Test1{

6

7 }

将以下哪种方法插入行6是不合法的。

Afloat  aMethodfloat  afloat  b{ }

Bpublic  int  aMethodint aint bthrows  Exception{ }

Cpublic  float  aMethodfloat  pfloat q{ }

Dpublic  int  aMethodint aint  bthrows IOException{ }

6)设有如下代码:

 try {

     tryThis();

     return;

 } catch (IOException x1) {

     System.out.println("exception 1");

     return;

 } catch (Exception x2) {

     System.out.println("exception 2");

     return;

 } finally {

     System.out.println("finally");

 }

如果tryThis() 抛出 NumberFormatException,则输出结果是?

A. 无输出

B. "exception 1", 后跟 "finally"

C. "exception 2", 后跟 "finally"

D. "exception 1"

E. "exception 2"

十三、流式输入输出与文件处理

1)以下哪个是RandomAccessFile文件的构造方法: 

ARandomAccessFile("data", "r");

BRandomAccessFile("r", "data");

CRandomAccessFile("data", "read");

DRandomAccessFile("read", "data");

2)设有如下代码:

import java.io.*;

public class Th{

   public static void main(String argv[]){

      Th t = new Th();

      t.amethod();

    }

   public void amethod(){

      try{

        ioCall();

      }catch(IOException ioe){}

   }

}

以下哪个最有可能是ioCall方法的方法体?

A public void ioCall () throws IOException{

      DataInputStream din = new DataInputStream(System.in);

      din.readChar();

    }

B public void ioCall () throw IOException{

      DataInputStream din = new DataInputStream(System.in);

      din.readChar();

   }

C public void ioCall (){

      DataInputStream din = new DataInputStream(System.in);

      din.readChar();

    }

D public void ioCall throws IOException(){    

      DataInputStream din = new DataInputStream(System.in);

      din.readChar();

   }

3)当前目录不存在名为Hello.txt的文件,执行下面代码的输出结果为?

import java.io.*;

public class Mine{

   public static void main(String argv[]){

       Mine m=new Mine( );

       System.out.println(m.amethod());

   }

   public int amethod(){

      try{

         FileInputStream file=new FileInputStream("Hello.txt");

      }

      catch(FileNotFoundException e){

          System.out.print("No such file found");

          return -1;

      }

      catch(IOException e){

         System.out.print("Doing finally");

      }

      return 0;

   }

}

A. No such file found

B. No such file found-1

C. No such file foundDoing finally-1

D. 0

4 使用哪个类可创建目录?

A File           B DataOutput     C Directory

D FileDescriptor      E.  FileOutputStream

5 假设raf是一个随机访问文件,以下语句的编译和运行结果为?raf.seek( raf.length() );

A.代码不能编译.

B.会出现IOException

C.文件指针将定位到文件的最后一个字符之前

D.文件指针将定位到文件的最后一个字符

6)以下哪些是FileOutputStream 构造方法的合法形式?

A FileOutputStream( FileDescriptor fd )

B FileOutputStream( String n, boolean a )

C FileOutputStream( boolean a )

D FileOutputStream()

E FileOutputStream( File f )

7)以下哪个能编译通过?

AFile f = new File("/","autoexec.bat");

B. DataInputStream d = new DataInputStream(System.in);

C. OutputStreamWriter o = new OutputStreamWriter(System.out);

D. RandomAccessFile r = new RandomAccessFile("OutFile");

8)以下程序的调试结果为:

import java.io.*;

class Base{

    public void amethod()throws FileNotFoundException{}

}

public class ExcepDemo extends Base{

    public static void main(String argv[]){

     ExcepDemo e = new ExcepDemo();

    }

    public void amethod(){}

    protected ExcepDemo(){

     try{

         DataInputStream din = new DataInputStream(System.in);

         System.out.println("Pausing");

         din.readByte();

         System.out.println("Continuing");

         this.amethod();

     }catch(IOException ioe) { }

    }

}

A. 由于构造方法为protected导致编译出错

B. 由于amethod方法未声明异常导致编译出错

C. 由于amethod方法未声明异常导致运行错误

D. 输出显示 "Pausing",击键后显示"Continuing"  

十四、多线程编程

1)什么原因可导致线程停止执行。

A.有更高优先级的线程开始执行;

B.线程调用了 wait()方法;

C.线程调用了yield()方法;

D.线程调用了 pause()方法;

E.线程调用了 sleep() 方法。

2)哪个方法是实现Runnable接口所需的?

Await()       Brun()        Cstop()

Dupdate()     Eresume()

3)以下代码的调试结果为?

public class Bground extends Thread{

public static void main(String argv[]){

      Bground b = new Bground();

      b.run();

 }

public void start(){

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

         System.out.println("Value of i = " + i);

     }

 }

}

A.编译错误,没有定义线程的run方法;

B.由于没有定义线程的run方法,而出现运行错误;

C. 编译通过,运行输出 values 0 to 9

D. 编译通过,运行无输出

4) 有关线程的叙述正确的有:

A.通过继承Thread类或实现Runnable接口,可以获得对类中方法的互斥锁定。

B. 可以获得对任何对象的互斥锁定。

C. 线程通过调用对象的synchronized 方法可取得对象的互斥锁定。

D. 线程调度算法是平台独立的。

5) 以下哪个是线程类的方法?

Ayield()

B. sleep(long msec)

C. go()

D. stop()

6)  以下哪个最准确描述synchronized关键字?

A.允许两线程并行运行,而且互相通信;

B. 保证在某时刻只有一个线程可访问方法或对象;

C. 保证允许两个或更多处理同时开始和结束;

D. 保证两个或更多线程同时开始和结束。

 

参考答案

一、

1) C 2)D 3) D 4) C 5) B 6) A

二、

1B 2C 3C 4B 5A 6E 7) B 8) BE 9) D 10B

11D 12ACD 13D 14B 15D 16) B

三、

1D 2) C 3) D 4) A 5B 6D 7) C 8) E 9)E 10) BC

11) A 12) D

四、

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

五、

1B 2D 3A 4C 5C 6B

六、

1B 2D 3C 4CD 5)C 6)B 7) B

七、

1A 2C 3B 4)D 5)C 6)A 7)A 8)D 9) D

八、

1C 2B 3D 4D 5ACD 6ABD 7A 8D 9C 10D

11AC 12ABD 13) D 14) AD

九、

1A 2B 3B 4D 5E 6A 7B 8A 9ABC

十、

1A 2C 3A 4)C 5)D 6)D 7) B 8)A

十一、

1A 2BE 3CE 4C 5A 6B 7C 8BD 9A 10AC

11B 12C

十二、

1C 2) AD 3) BCD 4) D 5) BCD 6) C

十三、

1) A 2) A 3) B 4) A 5) B 6) ABE 7) ABC 8) D

十四、

1ABCE 2B 3A 4CD 5ABD 6B

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值