?? mockcert04.txt
字號:
public class Test extends Applet{
public void init(){
setLayout(new BorderLayout());
add("South", new Button("B1"));
add("North", new Button("B2"));
add("South", new Button("B3"));
}
}
Select the correct statements regarding the above
Mutiple:
1) There are 2 buttons displayed in the SOUTH section, B1 and B3.
2) Only B3 is displayed in the SOUTH section.
3) An exception is thrown when an attempt is made to add a second component to SOUTH.
4) Only B1 is displayed in the SOUTH section.
5) You can't add buttons to applets.
Question 20
===========================================================
What is displayed when the following piece of code is executed:
1. String val = null;
2. int x = Integer.parseInt(val);
3.
4. System.out.println(x);
Mutiple:
1) 0
2) null
3) A NumberFormatException is thrown at line 2.
4) Nothing is displayed
Question 21
===========================================================
Consider the following piece of code:
class A{
int x = 0;
A(int w){
x = w;
}
}
class B extends A{
int x = 0;
B(int w){
x = w +1;
}
}
Mutiple:
1) The code compiles correctly.
2) The code fails to compile, because both class A and B do not have valid constructors.
3) The code fails to compile because there is no default no-args constructor for class A.
Question 22
===========================================================
Given an object myListener (whose class implements the ActionListener interface), which of the following are valid ways to enable myListener to receive all action events from component smallButton?
Mutiple:
1) smallButton.add(myListener);
2) smallButton.addListener(myListener);
3) smallButton.addActionListener(myListener);
4) smallButton.addItem(myListener);
Question 23
===========================================================
Which of the following are valid listener interfaces?
Mutiple:
1) ActionListener
2) MouseMotionListener
3) SystemEventListener
4) MouseClickListener
5) WindowListener
Question 24
===========================================================
Which of the following is the correct way to set the foreground colour of a component, c.
Mutiple:
1) c.setForeground("red");
2) c.setColor("Color.red");
3) c.Foreground(Color.red);
4) c.setForegroundColor("red");
5) c.setForeground(Color.red);
Question 25
===========================================================
Which of the following are valid ways to create a Map collection.
Mutiple:
1) Map m = new Map();
2) Map m = new Map(init capacity, increment capacity);
3) Map m = new Map(new Collection());
4) Map is an interface, and cannot be instantiated.
Question 26
===========================================================
Select all the correct statements relating to the following piece of code?
1. public class A{
2. abstract int method();
3. void anotherMethod(){
4. }
5.
6. class B extends A{
7. int method(){
8. return 2;
9. }
10. }
Mutiple:
1) Changing "extends" to "implements" on line 6 will allow the code to compile correctly.
2) The method() in class A cannot be abstract without the entire class being declared as abstract.
3) Declaring class A to be abstract will allow the code to compile correctly.
4) The class A must have an explicit default constructor in order for it to be subclassed correctly.
5) The code fails to compile, because class B does not implement anotherMethod().
Question 27
===========================================================
Which layout manager do the comments below refer to:
All components contained in it have the same width and height. Contained components are stretched to have the same dimensions.
Mutiple:
1) FlowLayout
2) BorderLayout
3) GridLayout
Question 28
===========================================================
Select all valid statements.
Mutiple:
1) When typing text into a TextField, scroll bars will automatically appear when the TextField becomes full.
2) When typing text into a TextArea, scroll bars will appear when text is typed past the boundaries of the TextArea.
3) TextFields can have more than 1 row of text.
4) The class TextArea is a super class of the class TextField.
5) Both TextAreas and TextFields have a method called setEditable(), which can enable or disable editingof the component.
Question 29
===========================================================
In which class is the paint() method defined?
Mutiple:
1) Object
2) Applet
3) Component
4) Thread
5) Graphics
Question 30
===========================================================
Select the statement which most closely describes the user interface of an applet with the following init() method:
public void init(){
Panel p = new Panel();
p.setLayout(new BorderLayout());
p.add(new Button("Hello"), BorderLayout.EAST);
p.add(new Button("Bye"), BorderLayout.WEST);
add(p);
}
Mutiple:
1) Two buttons are displayed. A button with "Hello" is on the right side of the applet. The button with "Bye" is on the left side of the applet. Both buttons extend from the centre of the applet to each side, and are the height of the applet.
2) Two buttons are displayed. A button with "Hello" is on the right side of the applet. The button with "Bye" is on the left side of the applet. Both buttons are only as wide as the text on the button, but are the height of the applet.
3) Two buttons are displayed. A button with "Hello" is on the right side of the applet. The button with "Bye" is on the left side of the applet. Both buttons are only large enough to support the associated button texts.
Question 31
===========================================================
What is wrong about the following piece of code (assume the relevant import statements are present):
public class Test{
public static void main (String [] args) throws IOException{
if (args[0] == "hello")
throw new IOException();
}
}
Only One:
1) Nothing. The code compiles correctly.
2) The code fails to compile. You can't throw an exception from the main() method.
3) The code fails to compile. IOException is a system exception, and cannot be thrown by application code.
Question 32
===========================================================
Consider the following piece of code, and select the statements which are true.
class Test{
int x = 5;
static String s = "abcd";
public static void method(){
System.out.println(s + x);
}
}
Mutiple:
1) The code compiles and displays "abcd5".
2) The code compiles, but throws an exception at runtime, because variable x isn't declared as static.
3) The code fails to compile because you can't make a static reference to a non-static variable.
4) The code will compile and display "abcd5" if x is declared to be static.
5) The code will compile by removing the static keyword from the declaration of method().
Question 33
===========================================================
Select all legal code fragments from the following.
Mutiple:
1) char c = "c";
2) Boolean b = new Boolean("qwerty");
3) String s = "null";
4) int q;
for (int p = 0, q = 0; p < 5; p++){
System.out.println("Val = " + p + q);
}
5) int x = 3;
Float f = new Float(x);
Question 34
===========================================================
Which of the following are legal ways to construct a RandomAccessFile?
Mutiple:
1) RandomAccessFile("file", "r");
2) RandomAccessFile("r", "file");
3) RandomAccessFile('r', "file");
4) RandomAccessFile("file", 'r');
5) RandomAccessFile("file", "rw");
Question 35
===========================================================
Consider the following code and select the most appropriate statements.
1. class Test{
2. public int doubleValue(int a)
3. System.out.println(a);
4. return (int)(a * 2);
5 }
6.
7 public float doubleValue(int a){
8. System.out.println(a);
9. return (float)(a * 2);
10. }
11.}
Mutiple:
1) The code compiles since the two doubleVal() methods have different return types.
2) The code doesn't compile because the compiler sees two methods with the same signature.
3) The code can be made to compile by redefining the parameter for doubleVal() on line 7 to be "float a" instead of "int a".
4) The code can be made to compile by replacing the public declaration on line 7 with private.
Question 36
===========================================================
What is displayed when the following piece of code is executed:
class Test extends Thread{
public void run(){
System.out.println("1");
yield();
System.out.println(2");
suspend();
System.out.println("3");
resume();
System.out.println("4");
}
public static void main(String []args){
Test t = new Test();
t.start();
}
}
Mutiple:
1) 1
2
3
4
2) 1
2
3
3) 1
2
4) Nothing. This is not a valid way to create and start a thread.
5) 1
Question 37
===========================================================
Consider the following piece of code, and select the most appropriate statements.
TextField t = new TextField("Hello", 20);
Mutiple:
1) The user will be able to edit the string.
2) The field will be 20 characters wide.
3) The text field will be same size on all platforms, since Java is platform independent.
4) When entering text into the field, only 20 characters can be entered.
5) If the font is changed, the size of the textfield will adjust to allow 20 characters to be displayed.
Question 38
===========================================================
True of False.
Using the instanceof operator on an interface will cause a runtime exception.
Only One:
1) True
2) False
Question 39
===========================================================
Which of the following are valid ways to create a Button component?
Mutiple:
1) new Button();
2) new Button(30, 10); where 30 is the width of the button and 10 is the height
3) new Button("hello");
4) new Button(new String("hello"));
5) new Button(String("hello"));
Question 40
===========================================================
Which of the following are NOT valid subclasses of AWTEvent?
Mutiple:
1) MouseClickEvent
2) OutputEvent
3) MouseMotionEvent
4) KeyAdapter
5) WindowMinimizeEvent
Question 41
===========================================================
Which of the following are valid methods for the Graphics class?
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -