2011年JAVA认证模拟题第二阶段(7)
Q19.Given the following hierarchical relationship of several classes.1. Object
2. |---TypeA
3. | |-----TypeAB
4. | |-----TypeAC
5. |--------TypeY And given the following method definition
6. public sayType(Object x ){
7. if(x instanceof Object )System.out.print(“Object,”);
8. if(x instanceof TypeA )System.out.print(“TypeA,”);
9. if(x instanceof TypeAB )System.out.print(“TypeAB,”);
10. if(x instanceof TypeAC )System.out.print(“TypeAC,”);
11. }What would the program output be if the following line was executed
12. sayType( new TypeAB() );
a. Object,
b. Object,TypeA,TypeAB,
c. TypeAB,
d. Object,TypeAC,
Q20.What happens on trying to compile and run the following code?
1. public class EqualsTest{
2. public static void main(String args[]){
3. Long LA = new Long( 9 ) ;
4. Long LB = new Long( 9 ) ;
2011年JAVA认证模拟题第二阶段(7)
</p> 5. if( LA == LB ) System.out.println(“Equal”);6. else System.out.println(“Not Equal”);
7. }
8. }
a. The program compiles but throws a runtime exception in line 5.
b. The program compiles and p rints “Not Equal”.
c. The program compiles and prints “Equal”.
d. The program throws compilation error.
Q21.Which one statement in true about the application below?
1. class StaticStuff {
2. static int x = 10;
3. static { x += 5; }
4. public s tatic void main(String args[]) {
5. System.out.println(“x = “ + x);
6. }
7. static { x /= 5; }
8. }
a. The code compiles, and execution produces the output x = 10.
b. The code compiles, and execution produces the output x = 15.
c. The code compiles, and execution produces the output x = 3.
d. Line 7 will not compile, because you can have only one static initializer.
19. b
20. b
21. c
页:
[1]