Java笔试题(个别答案为多选)

匿名网友 匿名网友 发布于: 2015-08-30 00:00:00
阅读 103 收藏 0 点赞 0 评论 0

1、
1. public class test{
2.   public static void main(String args[]){
3.     int  i =0xFFFFFFF1;
4.     int  j=~ i;
        5.
6.    }
7. }
  What is the decimal value of j at line 5?
(A) 0
(B) 1
(C) 14
(D) –15
(E) An error at line 3 causes compilation to fail.
(F) An error at line 4 causes compilation to fail.

2、
1. public class test{
2.   private static int j=0;
        3.
4.    private static Boolean methodB(int k){
5.     j+=k;
6.     return true;
7.   }
        8.
9.    public static void methodA(int  i){
10. Boolean b;
11. b= i <10|methodB(4);
12. b= i <10||methodB(8);
13. }
        14.
15. public static void main (String args[]){
16. methodA(0);
17.    System.out.println(j);
18.  }
19. }
What is the result?
(A) The program prints”0”
(B) The program prints “4”
(C) The program prints “8”
(D) The program prints “12”
(E) The code does not complete

3.
1. class BaseClass{
2.   private float x=1.0f;
3.   proteceted float getVar(){return x;}
4. }
5. class Subclass extends BaseClass{
6.   private float x=2.0f;
7.   //insert code here
8. }
Which two are valid examples of method overriding?(Choose Two)
(A) float getVar(){return x;}
(B) public float getVar(){return x;}
(C) float double getVar(){return x;}
(D) protected float getVar (){return x;}
(E) public float getVar(float f){return f;}

4.
Which statement is true?
(A) An anonymous inner class mau be declared as final
(B) An anonymous inner class can be declared as private
(C) An anonymous inner class can implement multiple interfaces
(D) Ananonymous inner class can access final variables in any enclosing scope
(E) Construction of an instance of a static inner class requires an instance of the enclosing outer class.

5.
1. interface Foo{
2.   int k=0;
3. }
4.
5.  public class Test implements Foo{
6. public static void main(String args[]){
7.   int i;
8.   Test test =new test();
9.   i =test.k;
10.   i =Test.k;
11.   i =Foo.k;
12. }
13.}
14.
What is the result?
(A) Compilation succeeds.
(B) An error at line 2 causes compilation to fail.
(C) An error at line 9 causes compilation to fail.
(D) An error at line 10 cause compilation to fail.
(E) An error zt line 11 causes compilation to fail.

6.
1. //point X
2. public class Foo{
3.   public static void main(String[]args)throws Exception{
4.     PrintWriter out=new PrintWriter (new
5.       java.io.OutputStreamWriter (System.out,true);
6.     out.println(“Hello”);
7.   }
8. }
Which statement at PointX on line 1 allows this code to compile and run?
(A) import java.io.PrintWriter;
(B) include java.io.PrintWriter;
(C) import java.io.OutputStreamWriter;
(D) include java.io.OutputStreamWriter;
(E) no statement is needed.

7.Which two statements are reserved words in java?(Choose Two)
(A) run
(B) import
(C) default
(D) implement

8.
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){retrun 4.0f;}

9.Which declaration prevents creating a subclass of an outer class?
(A) static class FooBar{}
(B) private class FooBar{}
(C) abstract public class FooBar{}
(D) final public class FooBar{}
(E) final abstract class FooBar{}

10.Which method is an appropriate way to determine the cosine of 42 degrees?
(A) double d=Math.cos(42);
(B) double d=Math.cosine(42);
(C) double d=Math.cos(Math.toRadians(42));
(D) double d=Math.cos(Math.toDegrees(42));
(E) double d=Math.cosine(Math.toRadians(42));

11.
You need to store elements in a collection that guarantees that no duplicates are stored and all elements can be accessed in natural order.
Which interface provides that capability?
(A) java.util.Map
(B) java.util.Set
(C) java.until.List
(D) java.util.StoredSet
(E) java.util.StoredMap
(F) java.util.Collection

12.
1. import java.io.IOException;
2. public class ExceptionTest{
3.   public static void main(String[]args)
4.     try{
5.       methodA();
6.     }catch (IOException e){
7.      System.out.println(“Caught IOException”);
8.     }catch(Exception e){
9.      System.out.println(“Caught Exception”);
10.     }
11.   }
12.   public void mehtodA(){
13.     throw new IOException();
14.   }
15. }
What is the result?
(A) The code will not compile.
(B) The output is caught exception.
(C) The output is caught IOException.
(D) The program executes normally without printing a message.

13.
1. public class Foo implement Runnable{
2.   public void run(Thread t){
3.     System.out.println(“Running.”);
4.   }
5.   public static void main(String[]args){
6.     new Thread(new Foo()).start();
7.   }
8. }
What is the result?
(A) An exception is thrown
(B) The program exists without printing anything
(C) An error at line 1 causes compilation to fail.
(D) An error at line 2 causes the compilation to fail.
(E) “Running”is printed and the program exits

14.Which statement is true?
(A) If only one thread is blocked in the wait method of an object, and another thread executes the modify on that same object,then the first thread immediately resumes execution.
(B) If a thread is blocked in the wait method of an object,and another thread executes the notify method on the same object,it is still possible that the first thread might never resume execution.
(C) If a thread is blocked in the wait method of an object,and another thread executes the notify method on the same object,then the first thread definitelu resumes execution as a direct and sole consequence of noify call.
(D) If two threads are blocked in the wait method of one boject,and another thread executes the notify method on the same object,then the first thread that executed the wait call first definitely resumes execution as a direct and sole consequence of the notify call.

15.
Which two CANNOT directly cause a thread to stop executing?(Choose Two)
(A) Calling the yield method
(B) Calling the wait method on an object
(C) Calling the notify method on an object
(D) Calling the NotifyAll method on an object
(E) Calling the start method on another Thread object

评论列表
文章目录