北京方正春元科技发展有限公司面试?- 百度文库

ʱ : 北京方正春元科技发展有限公司面试?- 百度文库ϿʼĶ

Choices:

What will be the result of executing the following code?

// Filename; SuperclassX.java

package packageX;

public class SuperclassX {

protected void superclassMethodX() { }

int superclassVarX; }

// Filename SubclassY.java

1.package packageX.packageY; 2.

3.public class SubclassY extends SuperclassX 4.{

5.SuperclassX objX = new SubclassY();

6.SubclassY objY = new SubclassY();

7.void subclassMethodY() 8.{

9.objY.superclassMethodX();

10.int i;

11.i = objY.superclassVarX; 12.}

13.}

Choices:

A.Compilation error at line 5 B.Compilation error at line 9 C.Runtime exception at line 11 D.None of these

7:

What will be the result of executing the following code?

public static void main(String args[]) {

char digit = 'a';

for (int i = 0; i < 10; i++) {

switch (digit) {

case 'x' : {

int j = 0;

System.out.println(j); }

default : {

int j = 100;

System.out.println(j); } } }

int i = j;

System.out.println(i); }

Choices:

What will be the result of executing the following code?

public static void main(String args[]) {

char digit = 'a';

for (int i = 0; i < 10; i++) {

switch (digit) {

case 'x' : {

int j = 0;

System.out.println(j); }

default : {

int j = 100; System.out.println(j); } } }

int i = j;

System.out.println(i); }

Choices:

A.100 will be printed 11 times.

B.The code will not compile because the variable i cannot be declared twice within the main() method.

C.The code will not compile because the variable j cannot be declared twice within the switch statement.

D.None of these.

8:Which modifier should be applied to a method for the lock of object this to be obtained prior to excution any of the method body?

A.synchronized B.abstract C.final D.static

9:

Give the code fragment: if(x>4){

System.out.println(Test 1);} else if (x>9){

System.out.println(Test 2);} else {

System.out.println(Test 3);}

Which range of value x would produce of output Test 2? Give the code fragment: if(x>4){

System.out.println(Test 1);} else if (x>9){

System.out.println(Test 2);} else {

System.out.println(Test 3);}

Which range of value x would produce of output Test 2?

A.x<4 B.x>4 C.x>9 D.None

10:

What will happen when you attempt to compile and run the following code?

(Assume that the code is compiled and run with assertions enabled.)

public class AssertTest{

public void methodA(int i){

assert i >= 0 : methodB();

System.out.println(i); }

public void methodB(){

System.out.println(\

ϵͬͷxxxxx#qq.com(#滻Ϊ@)