JAVA筆試題選擇題

 

1下面哪個是正確的類聲明?假設每一段文本都做爲一個名稱爲Fred.java的文件的全部內容? a
a).
public class Fred{
public int x = 0;
public Fred (int x){
      this.x=x;
}
}
b).
public class fred{
public int x = 0;
public Fred (int x){
this.x=x;
}
}
c).
public class Fred extends MyBaseClass, MyOtherBaseClass{
public int x = 0;
public Fred(int xval){
   x=xval;
}
}
d).
protected class Fred{
private int x = 0;
private Fred (int xval){
     x=xval;
}
}

 

A. a)
B. b)
C. c)
D. d)

2.在類設計中,類的成員變量要求僅僅能夠被同一package下的類訪問,請問應該使用下列哪個修辭詞 d

A. protected
B. public
C. private
D. 不需要任何修辭詞

3.下面那個是Runable接口的方法?a


A. run
B. start
C. yield
D. stop

4.給出類框架如下:
class Example{
   private int x;
   //rest of class body…
}
假定通過java Example調用x,下列哪個語句能夠使得在Example.java的main方法中直接訪問x?       b


A. 聲明x爲public而不是private
B. 聲明x爲static而不是private
C. 聲明x爲protected而不是private
D. 聲明x爲final而不是private

5.給出:以下類
public class ReturnIt{
ReturnType methodA(byte x,double y){
   return (short)x/y*2;
}
}
對於在第二行的方法methodA,他的返回值的類型應該是 f

A. int
B. byte
C. long
D. short
E. float
F. double

6.下面列出的那個是java的保留字?                 b


A. if
B. goto
C. while
D. case
E. then

7.十進制變量i的值爲12,那麼八進制的變量i的值爲:                      d

A. O08
B. O10
C. O12
D. O14
E. O16

8.下列哪些說法是正確的?                              d


A. 在collection類樹上,最頂層的類叫做Collection
B. collection接口有個方法是enumerator
C. interator方法返回一個Vetor類的實例
D. set接口是爲了那些不重複的元素設計的

9.現有下列代碼片斷:
switch(x){
         case 1: System.out.println("Test 1");break;
         case 2:
         case 3: System.out.println("Test 2");break;
         default: System.out.println("end");
}
X爲何值時將輸出"Test 2"                                                                  c

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

10.public class Test{
public int aMethod(){
   static int i=0;
   i++;
   return i;
}
public static void main(String args[]){
           Test test = new Test();
test.aMethod();
int j=test.aMethod();
System.out.println(j);
}
}
結果是什麼?                                                    a

A. 編譯失敗
B. 編譯成功和程序打出"0"
C. 編譯成功和程序打出"1"
D. 編譯成功和程序打出"2"

11. 選擇有效的java命名                                                                                     a d
A. userName
B. %passwd
C. 3d_game
D. $charge
E. this


12. 變量 "result" 是 boolean類型,下列那些表達式是合法的                             a b
A. result = true;
B. if ( result ) { // do something... }
C. if ( result!= 0 ) { // so something... }
D. result = 1


13。You have the following code. Which numbers will cause "Test2" to be printed?                                                                                                           b c d
switch(x){
case 1:
System.out.println("Test1");
case 2:
case 3:
System.out.println("Test2");
break;
}
System.out.println("Test3");
}
A. 0    
B. 1
C. 2        
D. 3
E. 4   


14. Given the following code:
1) class Parent {
2) private String name;
3) public Parent(){}
4) }
5) public class Child extends Parent {
6) private String department;
7) public Child() {}
8) public String getValue(){ return name; }
9) public static void main(String arg[]) {
10) Parent p = new Parent();
11) }
12) }
Which line will cause error?                                                                    d
A. line 3
B. line 6
C. line 7
D. line 8
E. line 10


15.class Parent {
String one, two;
public Parent(String a, String b){
one = a;
two = b;
}
public void print(){ System.out.println(one); }
}
public class Child extends Parent {
public Child(String a, String b){
super(a,b);
}
public void print(){
System.out.println(one + " to " + two);
}
public static void main(String arg[]){
Parent p = new Parent("south", "north");
Parent t = new Child("east", "west");
p.print();
t.print();
}
}
Which of the following is correct?                                                  e
A. Cause error during compilation.
B. south east
C. south to north east to west
D. south to north east
E. south east to west


16.下列代碼結果輸出多少行?                                                  d
public class Test {

public static void main(String args[]) {
int[][][] x = new int[3][][];
int j,i;
x[0] = new int[4][];
x[1] = new int[2][];
x[2] = new int[5][];
for(i=0;i<x.length;i++){
   for(j=0;j<x[i].length;j++){
    x[i][j]= new int[i+j+1];
    System.out.println();
    System.out.println("size = "+x[i][j].length);
   }
  
}

}
}
A, 8 B, 8 C,   10 D, 11   E, 12


17.Which two statements are true? (Choose two)                               b d
1. class A {
2. A() { }
3. }
4.
5. class B extends A {
6. }
A. Class B’s constructor is public.
B. Class B’s constructor has no arguments.
C. Class B’s constructor includes a call to this().
D. Class B’s constructor includes a call to super().


18. int i = 1,j = 10;
do {                
if(i>j) {        
break;
}                
j--;
} while (++i <5);
System.out.println(“i =” +i+” and j = “+j);                                     d
What is the result?
A. i = 6 and j = 5
B. i = 5 and j = 5
C. i = 6 and j = 4
D. i = 5 and j = 6
E. i = 6 and j = 6


19.What is the result?                                                             c
1. public class Test{
2. public static void aMethod() throws Exception {
3. try {
4. throw new Exception();
5. } finally {
6. System.out.println(“finally”);
7. }
8. }
9. public static void main(String args[]) {
10. try {
11. aMethod();
12. } catch (Exception e) {
13. System.out.println(“exception”);
14. }
15. System.out.println(“finished”);
16. }
17. }
A. finally
B. exception
finished
C. finally
exception
finished
D. Compilation fails.


20.下面那句話跟等於第二行的表達。(Choose three)         a b c
1. public interface Foo {
2. int k = 4;                                                                                
3. }
A. final int k = 4;
B. public int k = 4;
C. static int k = 4;
D. abstract int k = 4;
E. volatile int k = 4;
F. protected int k = 4;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章