`
gybmike
  • 浏览: 180354 次
  • 性别: Icon_minigender_1
  • 来自: 珠海
社区版块
存档分类
最新评论

java自测题一

阅读更多

Which are most typically thrown by an API developer or an 
application developer as opposed to being thrown by the JVM? (Choose all that apply.)

A. ClassCastException 

B. IllegalStateException 

C. NumberFormatException 

D. IllegalArgumentException 

E. ExceptionInInitializerError

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



Which declarations of identifiers are legal?
A. $persons
B. TwoUsers
C. *point
D. this
E. _endline

请选择:  A  B  C  D  E
答案:A B E
点评:Java的标识符可以以一个Unicode字符,下滑线(_),美元符($)开始,后续字符可以是前面的符号和数字,没有长度限制,大小写敏感,不能是保留字。


class BaseClass{ 
private float x=1.0f; 
private float getVar(){return x;} 
   } 
class SubClass extends BaseClass{ 
private float x=2.0f; 
//insert code 

what are true to override getVar()? 
A.float getVar(){ 
B.public float getVar(){ 
C.public double getVar(){ 
D.protected float getVar(){ 
E.public float getVar(float f){ 


请选择:  A  B  C  D  E
答案:A B D
点评:参数列表和返回值以及方法名(好像是费话)必须精确匹配,访问控制要更公有化

Which modifiers and return types would be valid in the declaration of a 
working main() method for a Java standalone application? 

A) private 
B) final 
C) static 
D) int 
E) abstract

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

How can you change the break statement below so that it breaks out of both the
inner and middle loops and continues with the next iteration of the outer loop?
outer: for (int x = 0; x < 3; x++) {
middle: for (int y = 0; y < 3; y++) {
inner: for (int z = 0; z < 3; z++) {
  if (arr(x, y, z) == targetValue)
    break;
  } } }
Select the one right answer.
a) break inner;
b) break middle;
c) break outer;
d) continue;
e) continue middle;

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

Which are not Java keywords? 
A. TRUE
B. sizeof
C. const
D. super
E. void

请选择:  A  B  C  D  E
答案:A B
点评: A:不是,Java中有true,但是这也不是关键字而是字面量(literal)。
B:不是,Java中不需要这个操作符,所有的类型(原始类型)的大小都是固定的。
C、D、E都是,需要说明的是const是java中未被使用的关键字。

Given:

public abstract interface Frobnicate { public void twiddle(String s) ; }

Which is a correct class? (Choose all that apply.)

A. public abstract class Frob implements Frobnicate { 

   public abstract void twiddle(String s){} 

  } 

B. public abstract class Frob implements Frobnicate { } 

C. public class Frob extends Frobnicate { 

     public void twiddle(Integer i) { } 
  
   } 

D. public class Frob implements Frobnicate { 

      public void twiddle(Integer i) { } 

   } 

E. public class Frob implements Frobnicate { 

    public void twiddle(String i) { } 

     public void twiddle(Integer s) { } 

    }

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

Which of the following statements is correct for a method which is overriding the
following method:
public void add(int a) {…}
A. the overriding method must return void
B. the overriding method must return int
C. the overriding method can return whatever it likes
Select the most appropriate answer.

请选择:  A  B  C
答案:A

Which are methods of the Object class? (Choose all that apply.)

A. notify(); 

B. notifyAll(); 

C. isInterrupted(); 

D. synchronized(); 

E. interrupt(); 

F. wait(long msecs); 

G. sleep(long msecs);

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

A socket object has been created and connected to a standard internet service on 
         a remote network server. Which construction give the most suitable means for
         reading ASCII data online at a time from the socket? 
   A. InputStream in=s.getInputStream(); 
   B. DataInputStream in=new DataInputstream(s.getInputStream()); 
   C. ByteArrayInputStream in=new ByteArrayInputStream(s.getInputStream()); 
   D. BufferedReader in=new BufferedReader(new InputStreamReader(s.getInputStream())); 
   E. BufferedReader in=new BufferedReader(new InputStreamReader(s.getInputStream()),”
        8859-1”); 


请选择:  A  B  C  D  E
答案:E
点评:在程序中实现字节与字符转换时,采用规范“ISO8859-1”是最适宜的方式。 

1)  class Super{ 
2)  public float getNum(){return 3.0f;} 
3)  } 
4) 
5)  public class Sub extends Super{ 
6) 
7)  } 
which method, placed at line 6, will cause a compiler error? 
A. public float getNum(){return 4.0f;} 
B. public void getNum(){} 
C. public void getNum(double d){} 
D. public double getNum(float d){return 4.0d;} 


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

1)  class Super{ 
2)  public float getNum(){return 3.0f;} 
3)  } 
4) 
5)  public class Sub extends Super{ 
6) 
7)  } 
which method, placed at line 6, will cause a compiler error? 
A. public float getNum(){return 4.0f;} 
B. public void getNum(){} 
C. public void getNum(double d){} 
D. public double getNum(float d){return 4.0d;} 


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

Which of the following statements are true?
A. For a given component events will be processed in the order the listeners are added.
B. Using the Adapter approach to event handling means there is a need to create blank
   method bodies for all event methods.
C. A component may have multiple listeners associated with it.
D. Listeners may be removed once added.


请选择:  A  B  C  D
答案:C D
点评:没有

Give the following java class: 
   public class Example{ 
   public static void main(String args[]){ 
   static int x[] = new int[15]; 
   System.out.println(x[5]); 
   } 
   } 
   Which statement is corrected? 
   A. When compile, some error will occur. 
   B. When run, some error will occur. 
   C. Output is zero. 
   D. Output is null.

请选择:  A  B  C  D
答案:A
点评:自动变量不能被static修饰,如果将static关键字去掉,答案选择C。

Which collection class(es) allows you to grow or shrink its size 
and provides indexed access to its elements, but whose methods are
not synchronized? (Choose all that apply.)

A. java.util.HashSet 

B. java.util.LinkedHashSet 

C. java.util.List 

D. java.util.ArrayList 

E. java.util.Vector 

F. java.util.PriorityQueue

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

public static synchronized void main(String[] args) throws
InterruptedException {
    Thread t = new Thread();
    t.start () ;
    System.out.print ("X") ;
    t.wait (10000) ;
    System.out.print("Y");
}

What is the result of this code?

A. It prints X and exits.

B. It prints X and never exits.

C. It prints XY and exits almost immeditately.

D. It prints XY with a 10-second delay between X and Y.

E. It prints XY with a 10000-second delay between X and Y.

F. The code does not compile.

G. An exception is thrown at runtime.

请选择:  A  B  C  D  E  F  G
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics