Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part A: Given the following 25. void doSomething() { 26. X x = doStuff(new X() ); 27. X y = doStuff(x); 28 x = null;

Part A:

Given the following

25. void doSomething() {

26. X x = doStuff(new X() );

27. X y = doStuff(x);

28 x = null;

29. y = null;

30. }

31. X doStuff(X x){

32 return doStuff2(x);

33. }

After which line of cade is the object created on line 26 eligible for garbage collection?

a. After line 28

b. After line 29

c. After line 30

d. The object will not become eligible

e. It is not possible to know from this code.

Part B;

Which one statement below is true concerning the following code?

1. class Greebo extends java.util.Vector

2. implements Runnable {

3. public void run(String message) {

4. System.out.println("in run() method: " +

5. message);

6. }

7. }

8.

9. class GreeboTest {

10. public static void main(String args[]) {

12. Greebo g = new Greebo();

13. Thread t = new Thread(g);

14. t.start();

15. }

16. }

A) There will be a compiler error, because class Greebo does not correctly implement the Runnable interface.

B) There will be a compiler error at line 13, because you cannot pass a parameter to the constructor of a Thread.

C) The code will compile correctly but will crash with an exception at line 13.

D) The code will compile correctly but will crash with an exception at line 14.

E) The code will compile correctly and will execute without throwing any exceptions.

Part C:

Which Man class properly represents the relationship Man has a best friend who is a Dog?

A. class Man extends Dog { }

B. class Man implements Dog { }

C. class Man { private BestFriend dog; }

D. class Man { private Dog bestFriend; }

E. class Man { private Dog }

F. class Man { private BestFriend }

Part D:

Given:

10. public class Bar {

11.static void foo(int...x) {

12. // insert code here

13. }

14. }

Which two code fragments, inserted independently at line 12, will allow the class to compile? (Choose two.)

A. foreach(x) System.out.println(z);

B. for(int z : x) System.out.println(z);

C. while( x.hasNext()) System.out.println( x.next());

D. for( int i=0; i< x.length; i++ ) System.out.println(x[i]);

Part E:

Given:

11. public class Test {

12. public static void main(String [] args) {

13. int x =5;

14. boolean b1 = true;

15. boolean b2 = false;

16.

17.if((x==4) && !b2)

18. System.out.print(l );

19. System.out.print(2 );

20. if ((b2 = true) && b1)

21. System.out.print(3 );

22. }

23. }

What is the result?

A. 2

B. 3

C. 1 2

D. 2 3

E. 1 2 3

F. Compilation fails.

G. An exceptional is thrown at runtime.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro SQL Server Administration

Authors: Peter Carter

1st Edition

1484207106, 9781484207109

More Books

Students also viewed these Databases questions