?? mockcert05.txt
字號:
3) class B implements A {
int method1(int i) { }
int method2(int j) { }
}
4) class B extends A {
int method1(int i) { }
int method2(int j) { }
}
5) class B implements A {
int method2(int j) { }
int method1(int i) { }
}
Question 73
===========================================================
Which of the following statements about try, catch, and finally are true?
Select all valid answers.
Mutiple: ________________
1) A try block must always be followed by a catch block
2) A try block can be followed either by a catch block or a finally block, or both
3) A catch block must always be associated with a try block
4) A catch block must always be associated with a try block
5) None of these are true
Question 74
===========================================================
Which best describes the user interface of an applet given the following init() method:
public void init() {
setLayout(new BorderLayout());
add("North", new TextField(10));
add("Center", new Button("help"));
}
Select all valid answers.
Mutiple: ________________
1) The TextField object will be placed at the top of the applet and will be 10 columns wide
2) The Button object will be centered in the applet and will be just large enough to contain the text "help"
3) The Button object will be centered in the applet and will start at the left edge of the applet, fit just under the TextField object above it, and extend to the right and bottom edge of the applet
4) The TextField object will be placed along the top of the applet and will stretch from the left edge to the right edge
5) The placement of the Button object and the TextField object depends on the overall size of the applet.
Question 75
===========================================================
Which Listener interfaces can you add to a TextArea object?
Mutiple: ________________
1) TextListener
2) ActionListener
3) MouseMotionListener
4) MouseListener
5) ComponentListener
Question 76
===========================================================
What appears in the standard output if the method named problem() in the code below throws an instance of class Exception when the method named trythis() is invoked?
public void trythis() {
try {
System.out.println("1");
problem();
} catch (RuntimeException x) {
System.out.println("2");
return;
} catch (Exception x) {
System.out.println("3");
return;
} finally {
System.out.println("4");
}
System.out.println("5");
}
Select all valid answers.
Mutiple: ________________
1) "1"
2) "2"
3) "3"
4) "4"
5) "5"
Question 77
===========================================================
Examine the following switch block:
char mychar = 'c';
switch (mychar) {
default:
case 'a': System.out.println("a"); break;
case 'b': System.out.println("b"); break;
}
Which of the following questions are definitely true?
Select all valid answers.
Mutiple: ________________
1) This switch block is illegal, because only integers can be used in the switch statement.
2) This switch block is fine.
3) This switch block is illegal, because the default statement must come last.
4) When this code runs, nothing is written to the standard output.
5) When this code runs, the letter "a" is written to the standard output.
Question 78
===========================================================
Which statements accurately describe the following line of code?
Select all valid answers.
String[][] s = new String[10][];
Mutiple: ________________
1) This line of code is illegal.
2) s is a two-dimensional array containing 10 rows and 10 columns
3) s is an array of 10 arrays.
4) Each element in s is set to ""
5) Each element in s is uninitialized and must be initialized before it is referenced.
Question 79
===========================================================
What will happen if you try to compile and run the following class?
class Test {
static int myArg = 1;
public static void main(String[] args) {
int myArg;
System.out.println(myArg);
}
}
Select the one right answer.
Mutiple: ________________
1) This code compiles and displays 0 in the standard output when run.
2) This code compiles and displays 1 in the standard output when run.
3) This code does not compile because you cannot define a local variable named the same as a static variable.
4) This code does not compile because the local variable is used before it is initialized.
Question 80
===========================================================
Which declarations for the main() method in a stand-alone program are NOT valid?
Select all valid answers.
Mutiple: ________________
1) public static void main()
2) public static void main(String[] string)
3) public static void main(String args)
4) static public int main(String[] args)
5) static void main(String[] args)
Question 81
===========================================================
Which of the following identifiers are ILLEGAL?
Select all valid answers.
Mutiple: ________________
1) #_pound
2) _underscore
3) 5Interstate
4) Interstate5
5) _5_
Question 82
===========================================================
Which interface implementations can you add as listeners for a TextField object?
Select all valid answers.
Mutiple: ________________
1) ActionListener
2) FocusListener
3) MouseMotionListener
4) WindowListener
5) ContainerListener
Question 83
===========================================================
What must be true for the RunHandler class so that instances of RunHandler can be used as written in the code below:
class Test {
public static void main(String[] args) {
Thread t = new Thread(new RunHandler());
t.start();
}
}
Select all valid answers.
Mutiple: ________________
1) RunHandler must implement the java.lang.Runnable interface.
2) RunHandler must extend the Thread class.
3) RunHandler must provide a run() method declared as public and returning void.
4) RunHandler must provide an init() method.
Question 84
===========================================================
To determine if you can invoke addContainerListener() for a component referenced using a variable named c, which expression(s) can you evaluate that will give you a true or false answer to this questions?
Select all valid answers.
Mutiple: ________________
1) c == Container
2) c.equals(Class.Container)
3) c instanceof Container
4) c instanceof Component
5) c implements Container
Question 85
===========================================================
What is written to the standard output given the following statement:
System.out.println(4 & 7);
Select the one right answer.
Mutiple: ________________
1) 4
2) 5
3) 6
4) 7
5) 0
Question 86
===========================================================
Given that the variable g references a valid Graphics object, what does the following statement do?
g.fillRect(2, 3, 10, 20);
Select all valid answers.
Mutiple: ________________
1) draw the outline of a rectangle in the current background color
2) draw the outline of a rectangle in the current foreground color
3) fill in a rectangle using the current background color
4) fill in a rectangle using the current foreground color
5) fill in a rectangle in black
Question 87
===========================================================
Describe the following applet.
import java.applet.Applet;
import java.awt.event.*;
import java.awt.*;
public class MyApplet extends Applet {
Button b1, b2;
public void init() {
ActionListener a = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (evt.getSource() == b1) {
b1.setEnabled(false);
b2.setEnabled(true);
} else {
b1.setEnabled(true);
b2.setEnabled(false);
}
}
};
b1 = new Button("1");
b1.addActionListener(a);
add(b1);
b2 = new Button("2");
b2.addActionListener(a);
add(b2);
}
}
Select all valid answers.
Mutiple: ________________
1) Nothing appears in the applet
2) Two buttons appear in the applet
3) When the user clicks a button, nothing happens
4) When the user clicks a button, it becomes disabled
5) When a user clicks a button, the other button becomes enabled
Question 88
===========================================================
The method setBackground() defined for the Graphics class:
Select all valid answers.
Mutiple: ________________
1) takes an integer value
2) takes an instance of class Color
3) takes an instance of a Component subclass
4) sets the drawing color for the associated Component object
5) changes the background color for the associated Component object
Question 89
===========================================================
What does the following program do when it is run with the command:
java Mystery Mighty Mouse
class Mystery {
public static void main(String[] args) {
Changer c = new Changer();
c.method(args);
System.out.println(args[0] + " " + args[1]);
}
static class Changer {
void method(String[] s) {
String temp = s[0];
s[0] = s[1];
s[1] = temp;
}
}
}
Select the one right answer.
Mutiple: ________________
1) This program causes an ArrayIndexOutOfBoundsException to be thrown
2) This program runs but does not write anything to the standard output
3) This program writes "Mighty Mouse" to the standard output
4) This program writes "Mouse Mighty" to the standard output
Question 90
===========================================================
What happens when you try to compile and run the following program?
class Mystery {
String s;
public static void main(String[] args) {
Mystery m = new Mystery();
m.go();
}
void Mystery() {
s = "constructor";
}
void go() {
System.out.println(s);
}
}
Select the one right answer.
Mutiple: ________________
1) this code will not compile
2) this code compiles but throws an exception at runtime
3) this code runs but nothing appears in the standard output
4) this code runs and "constructor" in the standard output
5) this code runs and writes "null" in the standard output
Question 91
===========================================================
What can you write at the comment //A in the code below so that this program writes the word "running" to the standard output?
class RunTest implements Runnable {
public static void main(String[] args) {
RunTest rt = new RunTest();
Thread t =new Thread(rt);
//A
}
public void run() {
System.out.println("running");
}
void go() {
start(1);
}
void start(int i) {
}
}
Select all valid answers.
Mutiple: ________________
1) System.out.println("running");
2) rt.start();
3) rt.go();
4) rt.start(1);
Question 92
===========================================================
What order can you place the following pieces of a source file in so that the source file will compile without errors or warnings?
//A
import java.applet.*;
//B
class Helper {}
//C
package myclasses;
//D
public class MyApplet extends java.applet.Applet {}
Select all valid answers.
Mutiple: ________________
1) A, B, C, D
2) A, C, B, D
3) C, A, B, D
4) C, A, D, B
5) C, B, A, D
Question 93
===========================================================
Analyze these two consequetive lines of code:
float f = 3.2;
int i = f;
Select all valid answers.
Mutiple: ________________
1) this code would not compile
2) this code would compile and i would be set to 3
3) the second line could compile if it were written instead as:
int i = (byte)f;
4) the first line could compile if it were written instead as:
float f = 3.2F;
Question 94
===========================================================
Question 41: What is the final value of temp in this sequence?
long temp = (int)3.9;
temp %= 2;
Only One: _______
1) 0
2) 1
3) 2
4) 3
5) 4
Question 95
===========================================================
Analyze this line of code:
if (5 & 7 > 0 && 5 | 2) System.out.println("true");
Select the one right answer.
Only One: _______
1) this line of code will not compile
2) this code will compile but nothing will appear in the standard output
3) this code will compile and write the word "true" in the standard output
Question 96
===========================================================
What will the user interface look like in an applet given the following init() method?
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -