Question: Part A: 1 class B { 2 private String name; 3 public B(String s) { 4 name = s; 5 } 6 public void finalize()

Part A:

1 class B {

2 private String name;

3 public B(String s) {

4 name = s;

5 }

6 public void finalize() {

7 System.out.print(name);

8 }

9 }

10

11 class E {

12 public static void m() {

13 B x1 = new B("X"), y1 = new B("Y");

14 }

15 public static void main(String[] args) {

16 m();

17 System.gc();

18 }

19 }

If the above is stored in a file called E.java, which 2 of the following could be a result of attempting to compile and run the program?

a. Prints: XY

b. Prints: YX

c. Prints: XXYY

d. Nothing is printed.

e. None of the above

f. Compilation error

g. An exception is thrown

Part B:

class JJF1 {

public void main (String args[]) {

System.out.print(Byte.MIN_VALUE+",");

System.out.print(Byte.MAX_VALUE); } }

What is the result of attempting to compile and run the program?

a. Prints: 0,255

b. Prints: 0,256

c. Prints: -127,128

d. Prints: -128,127

e. Compile-time error

f. None of the above

Part C:

1 class A {

2 void m1(int i) {

3 int j = i % 3;

4 switch (j) {

5 case 0: System.out.print("0");

6 break;

7 case 1: System.out.print("1");

8 break;

9 default:

10 assert (j == 2);

11 System.out.print(j);

12 }

13 }

14 public static void main (String[] args) {

15 A a = new A();

16 for (int i=5; i >= -1; i--) {a.m1(i);}

17 }

18 }

Which statements are true? Choose 2.

a. With assertions enabled it prints 210210-1 followed by an AssertionError message.

b. With assertions enabled it prints 210210 followed by an AssertionError message.

c. With assertions enabled it prints only 210210.

d. With assertions enabled it prints nothing.

e. With assertions disabled it prints 210210-1

f. With assertions disabled it prints only 210210

g. Assertions should not be used within the default case of a switch statement.

Part D:

Which of these words belong to the set of Java keywords? Choose 2

a. transient

b. serializable

c. runnable

d. run

e. volatile

f. externalizable

g. cloneable

Part E:

class A {

static int m(int i) {

System.out.print(i + ", ");

return i;

}

public static void main(String s[]) {

int i = 1;

m(m(++i) + m(i++) + m(-i) + m(i++));

}

}

What is the result of attempting to compile and run the above program? Choose 1.

a. Prints: 1, 2, 3, 4, 10,

b. Prints: 1, 2, -3, 4, 4,

c. Prints: 2, 2, -3, -3, -2,

d. Prints: 2, 2, -3, 3, 4,

e. Prints: 2, 3, -3, -2, 0,

f. Prints: 2, 3, -3, 4, 6,

g. Prints: 2, 3, 4, 5, 14,

h. Run-time error

i. Compile-time error

j. None of the above

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!