📄 mockcert02.txt
字号:
1) True
2) False.
Question 51
===========================================================
Consider the following piece of code and select the correct statement(s):
1. class A{
2. protected int method(){
3. }
4. }
5.
6. class B extends A{
7. int method(){
8. }
9. }
Mutiple:
1) The code fails to compile, because you can't override a method to be more private than its parent.
2) The code fails to compile, because method() is declared as protected, and is therefore not available to any subclass.
3) The code compiles correctly, but throws a NullPointerException at runtime.
4) The code fails to compile. However, it can be made to compile correctly by prefixing line 7 with the access qualifier "public".
5) The code fails to compile. However, it can be made to compile correctly by prefixing line 7 with the access qualifier "protected".
Question 52
===========================================================
True or False.
The Throwable class is the superclass of all exceptions in the Java language.
Only One:
1) True
2) False
Question 53
===========================================================
Consider the following piece of code (assume the Graphics context g is defined correctly):
g.setBackground(Color.red);
g.setForeground(Color.white);
g.drawLine(10, 10, 50, 10);
g.setForeground(Color.blue);
g.drawRect(100, 100, 50, 50);
What is displayed when this code is execute.
Only One:
1) A blue line from (10,10) to (50,10) and a blue rectangle with upper left corner at (100,100).
2) A white line from (10,10) to (50,10) and a blue square with top left corner at (100,100).
3) A white line from (10,10) to (10,50) and a blue square with lower left corner at (100,100).
4) A red line from (10, 10) to (50,10) and a red square with upper left corner at (100,100).
5) Nothing is displayed. You must first issue a repaint() command.
Question 54
===========================================================
Consider the following piece of code.
这题答案不对
class Test{
public static void main(String [] args){
System.out.println(args[3]);
}
}
When the following is typed at the command line, what is displayed:
java Test Metallica Justice For A
Only One:
1) All
2) For
3) Justice
4) Nothing
5) Nothing. An ArrayIndexOutOfBoundsException is thrown
Question 55
===========================================================
Consider the following piece of code.
1. String s = "abcd";
2. Integer x = new Integer(3);
3. String s2 = s + 4;
4. s2 = null;
5. s = null;
Following the execution of which line above, is the object referenced by s2 available for garbage collection.
Only One:
1) Line 5
2) It is not possible to say when an object is available for garbage collection.
3) Line 4
4) The objects are not available until the executing thread is ended.
Question 56
===========================================================
What is displayed when the following piece of code is compiled and executed:
class Test{
public static void main(String [] args){
Base b = new Subclass();
System.out.println(b.x);
System.out.println(b.method());
}
}
class Base{
int x = 2;
int method(){
return x;
}
}
class Subclass extends Base{
int x = 3;
int method(){
return x;
}
}
Only One:
1) Nothing. The code fails to compile because the object b is not created in a valid way.
2) 2
3
3) 2
2
4) 3
3
5) 3
2
Question 57
===========================================================
What is displayed when the following is executed:
String s1 = "aaa";
s1.concat("bbb");
System.out.println(s1);
Only One:
1) The string "aaa".
2) The string "aaabbb".
3) Nothing. concat() is not a valid method in the String class.
4) The string "bbbaaa".
5) The string "bbb".
Question 58
===========================================================
True or False.
The following is a valid way to construct a StringBuffer.
StringBuffer sb1 = "abcd";
Only One:
1) True
2) False
Question 59
===========================================================
What is the output of the following piece of code:
1. int x = 6;
2. double d = 7.7;
3.
4. System.out.println((x > d) ? 99.9 : 9);
Only One:
1) 9
2) 9.0 //答案有错,应该是9.0
3) 99.9
4) Nothing. An ArithmeticException is thrown at line 4.
5) 6
Question 60
===========================================================
Which of the following applet tags are mandatory (select all the correct answers).
Mutiple:
1) CODE
2) WIDTH
3) HEIGHT
4) PARAM
5) ARCHIVE
Question 61
===========================================================
What is printed out following the execution of the code below:
1. class Test{
2. static 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 fails to compile because the String s isn't declared correctly.
2) The text "Val = null" is displayed.
3) The string "Val = " is displayed.
4) The text "null" is displayed.
5) A blank line of text is printed.
Question 62
===========================================================
True or False.
The StringBuffer class does not have a concat() method.
Only One:
1) True
2) False
Question 63
===========================================================
What is displayed when the following piece of code is executed (assume the graphics context, g, is correctly set up):
g.drawString("abc", 10, 10);
Only One:
1) The text "abc" with the lower left part of "a" located at x = 10, y = 10.
2) The text "abc" with the upper left part of "a" located at x = 10, y = 10.
3) Nothing. This is not a valid method.
Question 64
===========================================================
True or False.
Anonymous classes cannot have constructor.
Only One:
1) True
2) False
Question 65
===========================================================
To reference a JAR from a web page, which of the following keywords are used:
Mutiple:
1) jar
2) class
3) zip
4) archive
5) package
Question 66
===========================================================
Analyse the following 2 classes and select the correct statements.
class A{
private int x = 0;
static int y = 1;
protected int q = 2;
}
class B extends A{
void method(){
System.out.println(x);
System.out.println(y);
System.out.println(q);
}
}
Mutiple:
1) The code fails to compile because the variable x is not available to class B.
2) The code compiles correctly, and the following is displayed: 0 1 2
3) The code fails to compile because you can't subclass a class with private variables.
4) Removing the line "System.out.println(x)" will allow the code to compile correctly.
5) The compiler will complain that the variable x in class B is undefined.
Question 67
===========================================================
Which of the following interfaces can be used to manage a collection of elements, with no duplication.
Mutiple:
1) List
2) Vector
3) Set
Question 68
===========================================================
Which of the following statements are true regarding inner classes.
Mutiple:
1) Variables defined inside inner classes cannot be static.
2) Variables defined inside inner classes cannot be static unless the inner class itself is static.
3) Non-static inner classes (which are not defined in a method) have access to all class and instance variables, regardless of the access qualifier of those variables.
4) Non-static inner classes (which are not defined in a method) have access to all class and instance variables, regardless of the access qualifier of those variables.
5) Inner classes can be declared as private. Top level, outer classes cannot.
Question 69
===========================================================
Which of the following are valid ways to define an abstract method.
Mutiple:
1) abstract void Test();
2) abstract void Test() {}
3) static abstract void Test();
4) final abstract void Test();
5) Methods cannot be defined as abstract, only variables can be abstract.
Question 70
===========================================================
Consider the following:
class A extends Integer{
int x = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -