急急急!!! JAVA考題 請程式高手回答 謝謝 40點

急急急!!! 請回答如下題目 最好能附解說更好 @@" 謝謝 ^ ^

Question 11)

What will be the result of attempting to compile and run the following code?

abstract class MineBase {

abstract void amethod();

static int i;

}

public class Mine extends MineBase {

public static void main(String argv[]){

int[] ar=new int[5];

for(i=0;i < ar.length;i++)

System.out.println(ar[i]);

}

}

1) a sequence of 5 0's will be printed

2) Error: ar is used before it is initialized

3) Error Mine must be declared abstract

4) IndexOutOfBoundes Error

Question 12)

What will be printed out if you attempt to compile and run the following code ?

int i=1;

switch (i) {

case 0:

System.out.println("zero");

break;

case 1:

System.out.println("one");

case 2:

System.out.println("two");

default:

System.out.println("default");

}

1) one

2) one, default

3) one, two, default

4) default

Question 13)

What will be printed out if you attempt to compile and run the following code?

int i=9;

switch (i) {

default:

System.out.println("default");

case 0:

System.out.println("zero");

break;

case 1:

System.out.println("one");

case 2:

System.out.println("two");

}

1) default

2) default, zero

3) error default clause not defined

4) no output displayed

Question 14)

Which of the following lines of code will compile without error

1)

int i=0;

if(i) {

System.out.println("Hello");

}

2)

boolean b=true;

boolean b2=true;

if(b==b2) {

System.out.println("So true");

}

3)

int i=1;

int j=2;

if(i==1|| j==2)

System.out.println("OK");

4)

int i=1;

int j=2;

if(i==1 &| j==2)

System.out.println("OK");

Update:

Question 15)

What will be output if you try to compile and run the following code, but there is

no file called Hello.txt in the current directory?.

import java.io.*;

public class Mine {

public static void main(String argv[]){

Mine m=new Mine();

Update 2:

System.out.println(m.amethod());

}

public int amethod() {

try {

FileInputStream dis=new FileInputStream("Hello.txt");

}catch (FileNotFoundException fne) {

Update 3:

System.out.println("No such file found");

return -1;

}catch(IOException ioe) {

} finally{

System.out.println("Doing finally");

}

Update 4:

return 0;

}

}

Update 5:

1) No such file found

2 No such file found ,-1

3) No such file found, Doing finally, -1

4) 0

Update 6:

Question 16)

Which of the following statements are true?

1) Methods cannot be overriden to be more private

2) static methods cannot be overloaded

3) private methods cannot be overloaded

4) An overloaded method cannot throw exceptions not checked in the base class

Update 7:

Question 17)

What will happen if you attempt to compile and run the following code?

class Base {}

class Sub extends Base {}

class Sub2 extends Base {}

public class CEx{

Update 8:

public static void main(String argv[]){

Base b=new Base();

Sub s=(Sub) b;

}

Update 9:

}

1) Compile and run without error

2) Compile time Exception

3) Runtime Exception

Update 10:

Question 18)

Which of the following statements are true?

Update 11:

1)System.out.println( -1 >>> 2);will output a result larger than 10

2) System.out.println( -1 >>> 2); will output a positive number

3) System.out.println( 2 >> 1); will output the number 1

4) System.out.println( 1 <<< 2); will output the number 4

Update 12:

Question 19)

What will happen when you attempt to compile and run the following code?

public class Tux extends Thread{

Update 13:

static String sName = "vandeleur";

public static void main(String argv[]){

Tux t = new Tux();

t.piggy(sName);

System.out.println(sName);

Update 14:

}

public void piggy(String sName){

sName = sName + " wiggy";

start();

}

public void run(){

Update 15:

for(int i=0;i < 4; i++){

sName = sName + " " + i;

Update 16:

}

}

Update 17:

}

1) Compile time error

2) Compilation and output of "vandeleur wiggy"

3) Compilation and output of "vandeleur wiggy 0 1 2 3"

Update 18:

4) Compilation and output of either "vandeleur", "vandeleur 0", "vandeleur 0 1" "vandaleur 0 1 2" or "vandaleur 0 1 2 3"

Update 19:

Question 20)

What will be displayed when you attempt to compile and run the following code

//Code start

import java.awt.*;

public class Butt extends Frame{

1 Answer

Rating
  • Anonymous
    1 decade ago
    Favorite Answer

    15題之前我回答再另外一個地方!!!

    (15) 這將是輸出如果您嘗試編譯並運行下面的代碼,但沒有文件要求Hello.txt當前目錄。

    A: 3. No such file found, Doing finally, -1

    這程式有點小複雜。

    1.amethod()方法裡面 , try(嘗試) 去捕捉dis這個物件的執行錯誤

    但因為沒有hello.txt這個檔案!! 所以會發生錯誤而捕捉到!!

    所以執行catch裡面的東西!! 所以回傳 -1 跟 印出No such….

    而finally這代表不管怎樣都會被執行捕捉後的動作!!

    所以還會印出Doing….

    這樣了解嗎?

    (16) 以下何者為正確的?

    這題我不能保證全部都正確哦!!! ((抱歉))

    (1)Methods cannot be overriden to be more private (Methods不能可重載private類型)

    應該是可以的!! 除非是Protected

    (2)static methods cannot be overloaded (static方法不可以重載)

    嗯…既然是靜態的!! 就不可以。

    (3)private methods cannot be overloaded (private方法不能重載)

    跟第一題一樣…應該是可以的!!

    (4)An overloaded method cannot throw exceptions not checked in the base class

    (重載的方法不可以拋出沒被選中的class)

    對的。

    (17) What will happen if you attempt to compile and run the following code?

    會出現何種情況?

    3. Runtime Exception (執行時發生錯誤)

    因為Base cannot be cast to Sub

    (Base不能cast to Sub)

    (18) Which of the following statements are true?

    何者是正確的?

    (1)will output a result larger than 10 (輸出結果大於10)

    正確的!! 輸出為…1073741823

    (2)will output a positive number (輸出為正數)

    正確的!! 同上

    will output the number 1 (輸出為1)

    正確的!!

    will output the number 4 (輸出為4)

    錯誤的!! Java並不支援 a <<< b這個符號!!

    先這樣吧~~剩下的我晚點回答!!!

    2009-04-11 13:15:07 補充:

    (19) What will happen when you attempt to compile and run the following code?

    將會發生什麼事情?

    應該是4吧

    ↓不知道翻譯正不正確…輸出下列其中一個

    Compilation and output of either "vandeleur", "vandeleur 0", "vandeleur 0 1" "vandaleur 0 1 2" or "vandaleur 0 1 2 3"

    因為它是輸出 vandeleur!!

    2009-04-11 13:15:17 補充:

    (20)What will be displayed when you attempt to compile and run the following code

    將會出現什麼?

    3) One button occupying the entire frame saying Bye

    一個按鈕佔用整個畫面且出現 Bye

    2009-04-11 13:15:26 補充:

    (21)What will be output by the following code?

    會出現什麼?

    複選題!!!

    (1) Value for i=1 Value for j=1

    (跑完第一次 i = 1 時出現,j = 2的時候重新跑 i = 2)

    (2) Value for i=2 Value for j=1

    (j不可能大於2,所以出現這個!!! 而i小於三,所以只出現兩個)

    2009-04-11 13:15:34 補充:

    (22) Which statement is true of the following code?

    哪種說法正確?

    4. Runtime error, an exception will be thrown

    運作時有異常,不然將會拋出例外!!

    但會出現waiting!!

    2009-04-11 13:15:40 補充:

    (23) Which of the following methods can be legally inserted in place of the comment //Method Here ?

    下列哪個方法可以合法地插入comment //Method在這裡?

    (2)跟(3)可以!!

    (1)不能重載非public 的類別!!

    (4)同上

    2009-04-11 13:15:51 補充:

    (24) Which of the following will output -4.0

    下列何者可以輸出 -4.0

    (3)可以!!

    (1)、 (2) 輸出-5.0 、 -5

    (4)無法執行!! 它是代表兩數取最小值!!

    2009-04-11 13:15:57 補充:

    (25) What will happen if you attempt to compile and run the following code?

    會發生什麼情況?

    (2) 19 followed by 11 (出現19跟11)

    在java 1.5.0版以後有一個東西出現…autoboxing(自動拆箱)

    會自動轉換wrapper型別跟基本資料型別!!

    所以可以直接使用物件跟基本資料型別做運算!!!

    2009-04-11 13:16:07 補充:

    (26) If you run the code below, what gets printed out?

    如果執行會出現什麼?

    (1)ic

    s.substring(iBegin,iEnd)代表說…在s字串裡面

    取 iBegin後的一直到 iEnd之中的字串!!

    2009-04-11 13:16:14 補充:

    (27) If you wanted to find out where the position of the letter v (ie return 2) in the string s containing "Java", which of the following could you use?

    這一句英文我看不懂= =…

    找出信件v的位置(ie 回傳 2)? 這是什麼意思…

    mid(2,s); ←沒看過這函數

    charAt(2); ←找出第二個字元

    s.indexOf('v'); ←找出v的位置

    indexOf(s,'v'); ←找出s之後第一個v的位置

    2009-04-11 13:16:48 補充:

    (28)看下列的式子,找出合法的。

    (1)、(4) 是合法的!!

    (2)、(3) 不可以!! (2)字串沒在相減的 (3)字串無法作位元邏輯運算

    2009-04-11 13:16:55 補充:

    (29) 會印出何者?

    答案為 (4)

    4 | 3 → 4 Or 3 (4 (Or邏輯閘) 3 )

    有學過數位邏輯嗎? 做個簡單說明

    4的二進位為 100 3的二進位為 11

    4 Or 3 == 100 Or 011 == 111 == 7

    2009-04-11 13:17:01 補充:

    (30)何者在XX位置上為合法的修飾字?

    1.2.3都可以!!

    4是什麼= =… java沒這個修飾字哦!!!

    這題目是來亂的嗎…哈哈!!!

    2009-04-11 13:17:15 補充:

    終於補充完了...很累= =

    若還有不懂的可以發問^^

    2009-04-14 18:25:53 補充:

    補充第27題!!

    答案是C

    s.indexOf('v');

    letter是當作字母的意思...謝謝THC大大提醒^^

    所以...找出s字串當中v的位置 (傳回索引值)

    Source(s): 自己
Still have questions? Get your answers by asking now.