java自测题二

Which are keywords in Java?
A. NULL
B. sizeof
C. friend
D. extends
E. synchronized

请选择:  A  B  C  D  E
答案:D E

public class X{ 
   public static void main(String[] args){ 
     int[] a=new int[1]; 
    4) modify(a); 
     System.out.println(a[0]); 
     } 
     public static void modify(int[] a){ 
    9) a[0]++;} 
      } 
    what is the result? 
    A.The program runs and prints "0"; 
    B.The program runs and prints "1"; 
    C.The program runs but aborts with an exception; 
    D.An error "possible undefined variable" at line 4 cause compilation to fail; 
    E.An error "possible undefined variable" at line 9 cause compilation to fail; 




请选择:  A  B  C  D  E
答案:B

An object is ... 

A) what classes are instantiated from. 
B) an instance of a class. 
C) a blueprint for creating concrete realization of abstractions. 
D) a reference to an attribute. 
E) a variable.

请选择:  A  B  C  D
答案:B


Which of the following statements about variables and their scopes are true?
  A. Instance variables are member variables of a class.
  B. Instance variables are declared with the static keyword.
  C. Local variables defined inside a method are created when the method is executed.
  D. Local variables must be initialized before they are used.
  

请选择:  A  B  C  D
答案:A C D
点评:类中有几种变量,分别是:局部变量(英文可以为:localautomatic emporarystack variable)是定义在方法里的变量;实例变量(英文为:instance variable)是在方法外而在类声明内定义的变量,有时也叫成员变量;类变量(英文为:class variable)是用关键字static声明的实例变量,他们的生存期分别是:局部变量在定义该变量的方法被调用时被创建,而在该方法退出后被撤销;实例变量在使用new Xxxx()创建该类的实例时被创建,而其生存期和该类的实例对象的生存期相同;类变量在该类被加载时被创建,不一定要用new Xxxx()创建,所有该类的实例对象共享该类变量,其生存期是类的生存期。任何变量在使用前都必须初始化,但是需要指出的是局部变量必须显式初始化,而实例变量不必,原始类型的实例变量在该类的构造方法被调用时为它分配的缺省的值,整型是0,布尔型是false,而浮点型是0.0f,引用类型(类类型)的实例变量的缺省值是null(没有进行实际的初始化,对它的使用将引起NullPointException),类变量的规则和实例变量一样,不同的是类变量的初始化是在类被加载时。



SCJP测试答案


如果你认为试题或答案有误,请你在留言板中通知站长!!



第29题(id号:150)

public class X{ 
    private static int a; 
    public static void main(String[] args){ 
     modify(a); 
     System.out.println(a); 
     } 
    public static void modify(int a){ 
      a++; 
     } 
     } 
   what is the result? 
A. 0
B. 1


请选择:  A  B
答案:A



Given the following expression about List.
  List l = new List(6,true);
  Which statements are ture?
  A. The visible rows of the list is 6 unless otherwise constrained.
  B. The maximum number of characters in a line will be 6.
  C. The list allows users to make multiple selections
  D. The list can be selected only one item.
  

请选择:  A  B  C  D
答案:A C
点评: List组件的该构造方法的第一个参数的意思是它的初始显式行数,如果该值为0则显示4行,第二个参数是指定该组件是否可以多选,如果值为true则是可以多选,如果不指定则缺省是不能多选。

The argument for a class's main() method is called args, and the class is invoked
as follows. java Example cat 
   What would be the effect of trying to access args[0] in the main method? 
   A. The value produced is cat 
   B. The value produced is java 
   C. The value produced is Example 
   D. An object of type NullPointerException is thrown. 
   E. An object of type ArrayIndexOutofBoundsException is thrown.

请选择:  A  B  C  D  E
答案:A
点评:命令行参数是紧跟在类名后面的。所以本题中参数由“cat”提供。 

Given the following code, which statements concerning the objects referenced 
through the member variables i, j and k are true, given that any thread may
call the methods a, b and c at any time? 

class Counter { 
int v = 0; 
synchronized void inc() { v++; } 
synchronized void dec() { v--; } 


public class Q7ed5 { 
Counter i; 
Counter j; 
Counter k; 

public synchronized void a() { 
    i.inc(); 
    System.out.println("a"); 
    i.dec(); 


public synchronized void b() { 
   i.inc(); 
   j.inc();
   k.inc(); 
   System.out.println("b"); 
   i.dec();
   j.dec(); 
   k.dec(); 


  public void c() { 
    k.inc(); 
    System.out.println("c"); 
    k.dec(); 
  } 


A) i.v is guaranteed always to be 0 or 1. 
B) j.v is guaranteed always to be 0 or 1. 
C) k.v is guaranteed always to be 0 or 1 
D) j.v will always be greater than or equal to k.v at any give time. 
E) k.v will always be greater than or equal to j.v at any give time. 


请选择:  A  B  C  D  E
答案:A B

Which three are valid declarations of a float? (Choose  Three) 
A. float foo = -1; 
B. float foo = 1.0; 
C. float foo = 42e1; 
D. float foo = 2.02f; 
E. float foo = 3.03d; 
F. float foo = 0x0123; 


请选择:  A  B  C  D  E  F
答案:A D F

What will happen when we try to compile the following code.
1. public void WhichArray( Object x ) {
2. if( x instanceof int[] ) {
3. int[] n = (int[]) x ;
4. for( int i = 0 ; i < n.length ; i++ ){
5. System.out.println("integers = " +n[i] );
6. }
7. }
8. if( x instanceof String[] ) {
9. System.out.println("Array of Strings");
10. }
11. }
a. The compiler objects to line 2 comparing an Object with an array.
b. The compiler objects to line 3 casting an Object to an array of int primitives.
c. The compiler objects to line 7 comparing an Object to an array of Objects.
d. It compiles without error.

请选择:  A  B  C  D
答案:D

你可能感兴趣的:(java,C++,c,C#,J#)