考古題:

https://www.javaworld.com.tw/

java Certification [精華區] 第2頁 ...網路資源...  考古題

 

 Signature     {method 名稱,傳入值型態,傳入值順序,傳入值個數}


父類別的
    1. 建構子跟
    2.  private的變數或方法

不會過繼給子類別




(21) Given:
1. int index = 1;
2. int [] foo = new int [3];
3. int bar = foo [index];
4. int baz = bar + index;

What is the result?
A. baz has the value of 0
B. baz has the value of 1    //沒有陷阱
C. baz has the value of 2
D. an exception is thrown
E. the code will not compile

(29) Given:
1. byte [ ] array1, array2[ ];
2. byte array3 [ ][ ];
3. byte[ ][ ] array4;

If each array has been initialized, which statement will cause a compiler error?
A. array2 = array1;
B. array2 = array3;
C. array2 = array4;
D. both A and B
E. both A and C
F. both B and C

延伸題目
    array2[0] = array1;     //OK
    array1[0] = array3[0];     //失敗 ,  byte v.s 陣列
    array4[0][0] = array1;     //失敗, 同上
    int [ ] [ ] array5 = array2 ;  // 失敗 array2是byte,不會自動升級
    Object o = array2;    //OK , 陣列都可以升級成物件 ,但Object不可以是陣列

(87) Given:
1. public class Test {
2. public static void main (String[] args){
3. String foo = args[1];                       //  args 參數 ,空白分隔,數量無限制
4. String bar = args[2];
5. String baz = args[3];
6. System.out.println("baz = " + baz);
7. }
8. }
And the output:
baz = 2

Which command line invocation will produce the output?
A. java Test 2222
B. java Test 1 2 3 4
C. java Test 4 2 4 2   //第四個參數
D. java Test 4 3 2 1

 




(10) Given:
1. class BaseClass {
2.    private float x = 1.0f ;
3.    protected 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;}

(8) Given:






1. public class ConstOver {





2. public ConstOver(int x, int y, int z){





3. }





4. }













Which two overload the ConstOver constructor? (Choose Two)






A. ConstOver( ){ }






B. protected int ConstOver( ){ }






C. private ConstOver(int z, int y, byte x){ }






D. public Object ConstOver(int x, int y, int z){ }






E. public void ConstOver(byte x, byte y, byte z){ }

 



(9) Given:




1. public class MethodOver {




2. public void setVar(int a, int b, float c){




3. }




4. }









Which two overload the setVar method? (Choose Two) //傳入值不同




A. private void setVar(int a, float c, int b){ }




B. protected void setVar(int a, int b, float c){ }




C. public int setVar(int a, float c, int b){return a;}




D. public int setVar(int a, int b, float c){return a;}




E. protected float setVar(int a, int b, float c){return c;}



(30) Click the exhibit button:
1. class Super {
2. public int i = 0;
4. public Super(String text){
5. i = 1;
6. }
7. }
8.
9. public class Sub extends Super {
10. public Sub (String text){
<----這裡會自動增加super();
11. i = 2;
12. }
13. public static void main (String args[]){
14. Sub sub = new Sub ("Hello");
15. System.out.println(sub.i);
16. }
17. }

What is the result?
A. Compilation will fail.
B. Compilation will succeed and the program will print "0".
C. Compilation will succeed and the program will print "1".
D. Compilation will succeed and the program will print "2".


Click the exhibit button:
1. class Super {
2. public int i = 0;
4. public Super(String text){
5. i = 1;
6. }
7. }
8.
9. public class Sub extends Super {
10. public void Sub (String text){ //一般方法
11. super(text);
12. }
13. public static void main (String args[]){
14. Sub sub = new Sub ("Hello");
15. System.out.println(sub.i);
16. }
17. }

What is the result?
A. Compilation will fail.
B. Compilation will succeed and the program will print "0".
C. Compilation will succeed and the program will print "1".
D. Compilation will succeed and the program will print "2".



private class Base{
protected Base(){
System.out.println("Base");
}
}
public class Test extends Base{
public static void main(String[] args){
Test a=new Test();
}
}

What will happen or printed out when you attempt to compile and run the class ?
1) Base
2) compile error , constructor can't be protected
3) compile error , class Test have no constructor
4) compile successfully, but no output
5) runtime exception
6) none of the above //編譯失敗,class權限沒有private
創作者介紹
創作者 撒姆爾紀事 的頭像
leavescat

撒姆爾紀事

leavescat 發表在 痞客邦 留言(0) 人氣( 204 )