?? mockcert04.txt
字號:
Question 1
===========================================================
What is displayed when the following piece of code is executed:
loop1:
for(int i = 0; i < 3; i++){
loop2:
for(int j = 0; j < 3; j++){
if (i == j){
continue loop2;
}
System.out.println("i = " + i + " j = " + j);
}
}
Only One:
1) i = 0
j = 0
i = 0
j = 1
i = 1
j = 0
i = 1
j = 1
i = 2
j = 0
i = 2
j = 1
2) i = 0
j = 0
i = 1
j = 1
i = 2
j = 2
3) i = 0
j = 1
i = 0
j = 2
i = 1
j = 0
i = 1
j = 2
i = 2
j = 0
i = 2
j = 1
4) None of the above.
Question 2
===========================================================
Consider the following piece of code, and select the correct statement(s):
long val = 2;
....
....
Switch (val){
default:
System.out.println("Default");
break;
case 1:
System.out.println("1");
break;
case 2:
System.out.println("2");
case 3:
System.out.println("3");
break;
}
Mutiple:
1) The following is displayed:
2
3
2) The following is displayed:
2
3) The code fails to compile because the default case must be the last case in the switch statement.
4) The code fails to compile because the argument for a switch statement cannot be a variable of type long.
5) The following is displayed:
2
3
Default
Question 3
===========================================================
Consider the following piece of code, and select the correct statement(s):
public class Test extends Applet{
public void init(){
setLayout(new GridLayout(1,2));
add(new Button("#1"));
add(new Button("#2"));
add(new Button("#3"));
add(new Button("#4"));
}
}
Only One:
1) The Gridlayout is created with 1 row and 2 columns.
2) Adding the button with the label "#3" will cause an exception to be thrown.
3) Adding the button with label "#3" will cause it to overwrite the button with label "#2".
4) The layout automatically extends to accommodate the additional buttons.
5) Only 2 buttons are displayed, one with label "#1" and one with label "#4".
Question 4
===========================================================
Which of the following layout managers will retain the preferred width and height of the contained components.
Mutiple:
1) GridLayout
2) GridBagLayout
3) BoxLayout
4) FlowLayout
5) BorderLayout
Question 5
===========================================================
You construct a List by calling List(5, false).
Which statements below are correct (assume the layout managers do not modify the List properties).
Mutiple:
1) The list supports multiple selection.
2) The list has 5 visible items.
3) A vertical scroll bar will be added automatically if needed.
4) The code fails to compile. The given constructor is not a valid one.
Question 6
===========================================================
Which of the following will definitely stop a thread from executing:
Mutiple:
1) wait()
2) notify()
3) yield()
4) suspend()
5) sleep()
Question 7
===========================================================
Which of the following is the correct method to call to change the layout manager for a container:
Only One:
1) setLayoutManager()
2) setLayManager()
3) changeLayout()
4) You can't change the layout manager for a container.
5) setLayout()
Question 8
===========================================================
Which is the correct way to add a button, referenced by b, to a panel, referenced by p.
Mutiple:
1) add(p, b);
2) p.add(b)
3) b.add(p)
4) Buttons can't be added to panels.
5) add(p)
Question 9
===========================================================
What is displayed when the following code is compiled and executed:
long val = 2;
switch(val){
case 1:
System.out.println("1");
case 2:
System.out.println("2");
default:
System.out.println("default");
}
Mutiple:
1) default
2) 2
default
3) The code fails to compile because there are no break statements in the case clauses.
4) The code fails to compile because a long data type is not a valid parameter for a switch statement.
Question 10
===========================================================
What is displayed following the execution of the code below:
1. class Test{
2. String s;
3. public static void main(String []args){
4. int x = 4;
5. if (x < 4)
6. System.out.println("Val = " + x);
7. else
8. System.out.println(s);
9. }
10. }
Only One:
1) Nothing. The code doesn't compile because the variable s wasn't initialised.
2) The string "null" is displayed.
3) The code runs, but a NullPointerException is thrown at line 8.
4) The code compiles. No exception is thrown but nothing is displayed.
5) Nothing. The code doesn't compile because you can't make a static reference to a non-static variable.
Question 11
===========================================================
Consider the following piece of code:
class Test{
int x;
String s;
float fl;
boolean [] b = new boolean [5];
public static void main(String []args){
System.out.println(x);
System.out.println(s);
System.out.println(fl);
System.out.println(b[2]);
}
}
What is displayed when this code is executed.
Only One:
1) 0
null
0.0
false
2) 0
""
0.0
true
3) Nothing. The code fails to compile because the boolean array is incorrectly declared.
4) Nothing. The code will not compile because the static method cannot access the variables since there is no instance of the Test class.
Question 12
===========================================================
What is displayed when the following code is compiled and executed:
String s = "abcd";
String s1 = new String(s);
if (s == s1)
System.out.println("the same");
if (s.equals(s1))
System.out.println("equals");
Only One:
1) the same
equal
2) equals
3) the same
4) The code compiles, but nothing is displayed upon execution.
5) The code fails to compile.
Question 13
===========================================================
What is the legal range for the byte data type:
Only One:
1) 0 to +255
2) -127 to +128
3) -128 to +127
4) 0 to 65535
5) -32767 to +32768
Question 14
===========================================================
What is displayed when the following code is executed:
String s = "abcdef";
System.out.println(s.charAt(4));
Mutiple:
1) d
2) e
3) Nothing. An ArrayIndexOutOfBoundsException is thrown
4) The code does not compile. charAt() is not a valid method of the String class.
5) The code does not compile because the string s is not created correctly.
Question 15
===========================================================
True or False.
The String class does not have an append() method.
Only One:
1) True
2) False
Question 16
===========================================================
Consider the following code segment.
double d = -11.1;
double d1 = method(d);
System.out.println(d1);
If the output of this code segment is -12.0, then what methods could be called in method() above.
Mutiple:
1) floor()
2) ceil()
3) round()
4) abs()
5) min()
Question 17
===========================================================
What outputs are possible from invoking Math.random().
Only One:
1) -0.12
0.56E3
2) 0.12
1.1E1
3) -23.45
0.0
4) 0.356
0.0
5) 1.00
0.99
Question 18
===========================================================
In a thread, the wait() method must be called inside which of the following:
Mutiple:
1) A while() loop
2) The run() method
3) synchronised code
4) The constructor
5) It doesn't matter where the wait() is called from.
Question 19
===========================================================
Consider the following piece of code:
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -