📄 mockcert02.txt
字号:
}
Select all valid statements.
Mutiple:
1) The code will compile correctly.
2) The code will not compile because Integer is final and cannot be subclassed.
3) The code will not compile because class A has no methods or constructor.
4) The code will compile correctly, but will throw an ArithmeticException at runtime.
Question 71
===========================================================
Consider the following and select the correct statement(s):
interface A{
int x = 0;
A(){
x= 5;
}
A(int s){
x = s;
}
}
Only One:
1) This is a valid piece of code and it compiles correctly.
2) The default constructor is not required since the compiler will create one for you.
3) The code fails to compile because interfaces cannot have more than 1 constructor.
4) The code fails to compile because an interface cannot have any constructors.
5) The code fails to compile, because a class must have more than 1 character in it's name.
Question 72
===========================================================
True or False.
A try block always needs a catch or a finally block (either or both, but not none).
Only One:
1) True
2) False
Question 73
===========================================================
Which of the following are valid ways to declare the main() method which is used to start a Java program.
Mutiple:
1) public static void main(String [] args)
2) static public void main(String [] args)
3) public void main(String args [])
4) public static void main(String args[])
5) public static void main(String args)
Question 74
===========================================================
Consider the following piece of code:
boolean b = true;
System.out.println(b);
What is displayed when this code is executed?
Only One:
1) The text "true" is displayed.
2) The text "1" is displayed
3) The code fails to compile, because conversion string conversion in ths System.out.println() method only applies to integers.
4) The code compiles but nothing is displayed upon execution.
5) The code fails to compile. However, changing the first line to "boolean b = TRUE;" will correctly declare a boolean, and the code will compile and display "1".
Question 75
===========================================================
Which of the following pieces of code compiles without any errors?
Mutiple:
1) StringBuffer sb1 = "abcd";
2) Boolean b = new Boolean("abcd");
3) byte b = 255;
4) int x = 0x1234;
5) float fl = 1.2;
Question 76
===========================================================
Which of the following are valid statements regarding the following piece of code?
1. String s1 = "abcd";
2. StringBuffer sb1 = new StringBuffer("abcd");
3. int val = 6;
4. System.out.println(s1 + val);
5. System.out.println(sb1 + val);
Mutiple:
1) The text "abcd6" is displayed followed by "abcd6".
2) The code fails to compile because String conversion does not apply to StringBuffer.
3) The code compiles but upon execution, throws a NullPointerException at line 5.
4) The code fails to compile at line 2, because this is not a valid way to create a StringBuffer.
5) The code fails to compile at line 1, because this is not a valid way to create a String.
Question 77
===========================================================
True or False.
Abstract methods can be declared as static.
Only One:
1) True
2) False
Question 78
===========================================================
FlowLayout is the default layout manager for which of the following containers:
Mutiple:
1) Panel
2) Applet
3) Frame
4) Window
5) Dialog
Question 79
===========================================================
In which class are the following methods defined:
- wait()
- notify()
- notifyAll(
Mutiple:
1) Thread
2) Runnable
3) Object
4) Event
5) Synchronize
Question 80
===========================================================
Which one of the following creates an instance of Vector with an initial capacity of 10, and an incremental capacity of 5.
Mutiple:
1) new Vector(10, 5);
2) new Vector(5,10);
3) None. There is no constructor of Vector which provides this feature.
4) None. There is no constructor of Vector which provides this feature.
5) Vector is declared as final, and it is therefore not possible to instantiate it.
Question 81
===========================================================
True of False.
CheckboxGroup is a subclass of Component.
Only One:
1) True
2) False
Question 82
===========================================================
Which statements(s) below are true about the following piece of code.
class Test implements Runnable{
public static void main(String [] args){
Thread t = new Thread(new Test());
t.start();
}
public void run(int limit){
for (int x = 0; x < limit; x++)
System.out.println(x);
}
}
Mutiple:
1) All the numbers up to (but not including) "limit" are printed out.
2) Nothing is displayed. There is no explicit call to the run() method.
3) The code fails to compile because the Runnable interface is not implemented correctly.
4) The code can be made to compile by declaring the class Test to be abstract.
5) The code can be made to compile by removing the words "implements Runnable".
Question 83
===========================================================
Consider the following code and select the statement(s) which are true:
1. class Test extends Frame{
2.
3. public static void main(String [] args){
4. Test t = new Test();
5. }
6.
7. Test(){
8. Button b = new Button("Hello");
9. add(b, BorderLayout.SOUTH);
10. }
11.
12. }
Mutiple:
1) The code compiles. When executed, nothing is displayed.
2) The code compiles. When executed, a button with the text "Hello" is located at the bottom on the screen. The button is as tall as the text, but is the width of the frame.
3) Adding in the following two lines between lines 9 and 10 will display a frame with a button at the bottom of the frame: setSize(100, 100); setVisible(true);
4) The code fails to compile, because a layout manager was not specified.
5) The code fails to compile because you cannot subclass the Frame class.
Question 84
===========================================================
Before which of the following can the keyword "synchronized" be placed, without causing a compile error.
Mutiple:
1) class methods
2) instance methods
3) any block of code within a method
4) variables
5) a class
Question 85
===========================================================
Consider the following class definitions:
class Base{}
class Subclass1 extends Base{}
class Subclass2 extends Base();
Now consider the following declarations:
Base b = new Base();
Subclass1 s1 = new Subclass1();
Subclass2 s2 = new Subclass2();
Now, consider the following assignment:
s1 = (Subclass1)s2;
Which of the following statements are correct regarding this assignment (select one).
Mutiple:
1) The assignment is legal and compiles without an error. No exception is thrown at runtime.
2) The code fails to compile. The compiler complains that the assignment "s1 = (Subclass1)s2" is illegal.
3) The code compiles but ClassCastException is thrown at runtime.
4) The code fails to compile. You cannot subclass a parent class more than once.
Question 86
===========================================================
Select all the valid ways of initialising an array.
Mutiple:
1) int x[] = {1,2,3};
2) int []x[] = {{1,2,3},{1,2,3}};
3) int x[3] = {1,2,3};
4) int []x = {0,0,0};
5) char c[] = {'a', 'b'};
Question 87
===========================================================
What is the valid declaration for the finalize() method.
Mutiple:
1) protected void finalize() throws Throwable
2) final finalize()
3) public final finalize()
4) private boolean finalize()
5) private final void finalize() throws Exception
Question 88
===========================================================
What is the method used to retrieve a parameter passed into an applet using the PARAM tag.
Mutiple:
1) getParam()
2) getParameter()
3) getVariable()
4) getVar()
5) There is no method available. You must use "String [] args" approach.
Question 89
===========================================================
You have a button, which is in a panel. The panel is inside a frame. You assign the Frame a 24-point font and a background colour of yellow. You set the panel to have a background colour of red. Which of the following statements are true (select all valid statements).
Mutiple:
1) The font size of the button is 24-point.
2) The background colour of the button is the same as that of the frame.
3) The panel has a font size of 8-point.
4) The button inherits the font from the panel.
5) This is not a valid configuration. It is not valid to place a panel into a frame.
Question 90
===========================================================
Consider the following piece of code and select the correct statement(s):
public class Test{
final int x = 0;
Test(){
x = 1;
}
final int aMethod(){
return x;
}
}
Mutiple:
1) The code fails to compile. The compiler complains because there is a final method ("aMethod") in a non-final class.
2) The code compiles correctly. On execution, an exception is thrown when the Test() constructor is executed.
3) The code fails to compile because an attempt is made to alter the value of a final variable.
4) Removing the "final" keyword from the line "final int x = 0" will allow the code to compile correctly.
5) The code fails to compile because only methods can be declared as final (and therefore "final int x = 0" is not valid).
Question 91
===========================================================
What is displayed when the following code fragment is compiled and executed (assume that the enveloping class and method is correctly declared and defined):
StringBuffer sb1 = new StringBuffer("abcd");
StringBuffer sb2 = new StringBuffer("abcd");
String s1 = new String("abcd");
String s2 = "abcd";
System.out.println(s1==s2);
System.out.println(s1=s2);
System.out.println(sb1==sb2);
System.out.println(s1.equals(sb1));
System.out.println(sb1.equals(sb2));
Only One:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -