想过Scjp必看,Scjp中几道经典问题,欢迎讨论!
76. Click the exhibit button.
ClassOne.java
1. package com.abc.pkg1;
2. public class ClassOne {
3. private char var = 'a';
4. char getVar() {return var;}
5. }
ClassTest.java
1. package com.abc.pkg2;
2. import com.abc.pkg1.ClassOne;
3. public class ClassTest extends ClassOne {
4. public static void main(String[]args) {
5. char a = new ClassOne().getVar();
6. char b = new ClassTest().getVar();
7. }
8. }
What is the result?
A. Compilation will fail.
B. Compilation succeeds and no exceptions are thrown.
C. Compilation succeeds but an exception is thrown at line 5 in ClassTest.java.
D. Compilation succeeds but an exception is thrown at line 6 in ClassTest.java.
78. Which two statements are true regarding the creation of a
default constructor? (Choose Two)
A. The default constructor initializes method variables.
B. The compiler always creates a default constructor for every
class.
C. The default constructor invokes the no-parameter
constructor of the superclass.
D. The default constructor initializes the instance variables
declared in the class.
E. When a class has only constructors with parameters, the
compiler does not create a default constructor.
101. Which statement is true?
A. The Error class is a untimeException.
B. No exceptions are subclasses of Error.
C. Any statement that may throw an Error must be enclosed in a try block.
D. Any statement that may throw an Exception must be enclosed in a try block.
E. Any statement that may thro a runtimeException must be enclosed in a try block.
133. Given:
1. public class ForBar {
2. public static void main(String []args) {
3. int i = 0, j = 5;
4. tp: for (; {
5. i ++;
6. for(;
7. if(i > --j) break tp;
8. }
9. System.out.println("i = " + i + ", j = "+ j);
10. }
11. }
What is the result?
A.The program runs and prints "i=1, j=0"
B.The program runs and prints "i=1, j=4"
C.The program runs and prints "i=3, j=4"
D.The program runs and prints "i=3, j=0"
E.An error at line 4 causes compilation to fail
F.An error at line 7 causes compilation to fail
142. Which two statements are true? (Choose Two)
A.An anonymous inner class can be declared inside of a method.
B.An anonymous inner class constructor can take arguments in some situation.
C.An anonymous inner class that is a direct subclass that is a
direct subclass of Object can implement multiple interfaces .
D.Even if a class Super does not implement any interfaces, it
is still possible to define an anonymous inner class that is
an immediate subclass of Super that implements a single
interface.
E.Event if a class Super does not implement any interfaces, it
is still possible to define an anonymous inner class that is
an immediate subclass of Super that implements multiple interfaces.