📄 83.txt
字号:
10道题,20分钟时间:
Q.1 (1-1)
Given
1 public class X{
2 public Object m(){
3 Object o = new Float(3.14F);
4 Object [] oa = new Object[1];
5 oa[0] = o;
6 o=null;
7 return oa[0];
8 }
9 }
When is the Float object, created in line 3,eligible for garbage collection?
A. just after line 5
B. just after line 6
C. just after line 7(that is,as the method returns)
D. never in this method
Q.2 (1-3)
Consider the following classes:
public class Test {
public static void test() {
this.print();
}
public static void print() {
System.out.println("Test");
}
public static void main(String args []) {
test();
}
}
What is the result of compiling and running this class?
A) The string Test is printed to the standard out.
B) A runtime exception is raised stating that an object has not been created.
C) Nothing is printed to the standard output.
D) An exception is raised stating that the method test cannot be found.
E) An exception is raised stating that the variable this can only be used within an instance.
F) The class fails to compile stating that the variable this is undefined.
Select all correct answers.
Q. 3 (1-10)
Which of these is the correct format to use to create the literal char value a?
A) ‘a’
B) "a"
C) new Character(a)
D) \000a
Select the most appropriate answer.
Q. 4 (2-1)
What will happen if you try to compile and execute B’s main() method?
class A {
int i;
A(int i) {
this.i = i * 2;
}
}
class B extends A {
public static void main(String[] args) {
B b = new B(2);
}
B(int i) {
Super();
System.out.println(i);
}
}
Select the one right answer.
a) The instance variable i is set to 4
b) The instance variable i is set to 2
c) The instance variable i is set to 0
d) This code will not compile
Q. 5 (2-3)
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.
a) this code will not compile
b) this code compiles but throws an exception at runtime
c) this code runs but nothing appears in the standard output
d) this code runs and "constructor" in the standard output
e) this code runs and writes "null" in the standard output
Q. 6(2-4)
public class Foo{
public static void main(String sgf[]){
StringBuffer a = new StringBuffer("A");
StringBuffer b = new StringBuffer("B");
operate(a,b);
System.out.println(a+","+b);
}
static void operate(StringBuffer x,StringBuffer y){
x.append(y);
y=x;
}
}
What is the result?
A. The code compiles and prints “A.B”.
B. The code compiles and prints “A.A”.
C. The code compiles and prints “B.B”.
D. The code compiles and prints “AB.B”.
E. The code compiles and prints “AB.AB”.
Q.7 [Check all correct answers] (3-4)
Which of the following statements will cause a compiler error.
a) float F=4096.0;
b) double D=4096.0;
c) byte B=4096;
d) char C=4096;
Q.8 (3-8)
Once created, some Java objects are "immutable", meaning they can not have their contents changed. Which of the following classed produce immutable objects?
a. java.lang.Double
b. java.lang.StringBuffer
c. java.lang.Boolean
d. java.lang.Math
Q. 9 (4-9)
Consider the following program:
public class Test {
public static void main (String args []) {
boolean a = false;
if (a = true)
System.out.println("Hello");
else
System.out.println("Goodbye");
}
}
What is the result:
A. Program produces no output but terminates correctly.
B. Program does not terminate.
C. Prints out "Hello"
D. Prints out "Goodbye"
Select the most appropriate answer.
Q.10(6-45)
Given the following class definition:
class A{
protected int i;
A(int i){
this.i=i;
}
}
which of the following would be a valid inner class for this class?
Select all valid answers:
A. class B{
}
B. class B extends A{
}
C. class B extends A{
B(){System.out.println(“i=”+i);}
}
D. class B{
class A{}
}
E.class A{}
答案:
1 2 3 4 5 6 7 8 9 10
D F A D E D A,C A,C C A
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -