Winter Sale Special Limited Time 65% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: v4s65

1z0-809 Exam Dumps - Java SE 8 Programmer II

Go to page:
Question # 17

Given:

public enum USCurrency {

PENNY (1),

NICKLE(5),

DIME (10),

QUARTER(25);

private int value;

public USCurrency(int value) {

this.value = value;

}

public int getValue() {return value;}

}

public class Coin {

public static void main (String[] args) {

USCurrency usCoin =new USCurrency.DIME;

System.out.println(usCoin.getValue()):

}

}

Which two modifications enable the given code to compile? (Choose two.)

A.

Nest the USCurrency enumeration declaration within the Coin class.

B.

Make the USCurrency enumeration constructor private.

C.

Remove the new keyword from the instantion of usCoin.

D.

Make the getter method of value as a static method.

E.

Add the final keyword in the declaration of value.

Full Access
Question # 18

Given:

and the code fragment:

Which definition of the ColorSorter class sorts the blocks list?

A.

B.

C.

D.

Full Access
Question # 19

Given:

class Worker extends Thread {

CyclicBarrier cb;

public Worker(CyclicBarrier cb) { this.cb = cb; }

public void run () {

try {

cb.await();

System.out.println(“Worker…”);

} catch (Exception ex) { }

}

}

class Master implements Runnable { //line n1

public void run () {

System.out.println(“Master…”);

}

}

and the code fragment:

Master master = new Master();

//line n2

Worker worker = new Worker(cb);

worker.start();

You have been asked to ensure that the run methods of both the Worker and Master classes are executed.

Which modification meets the requirement?

A.

At line n2, insert CyclicBarrier cb = new CyclicBarrier(2, master);

B.

Replace line n1 with class Master extends Thread {

C.

At line n2, insert CyclicBarrier cb = new CyclicBarrier(1, master);

D.

At line n2, insert CyclicBarrier cb = new CyclicBarrier(master);

Full Access
Question # 20

Given:

and the code fragment:

The threads t1 and t2 execute asynchronously and possibly prints ABCA or AACB.

You have been asked to modify the code to make the threads execute synchronously and prints ABC.

Which modification meets the requirement?

A.

start the threads t1 and t2 within a synchronized block.

B.

Replace line n1 with:private synchronized int count = 0;

C.

Replace line n2 with:public synchronized void run () {

D.

Replace line n2 with:volatile int count = 0;

Full Access
Question # 21

Given:

and the code fragment:

What is the result?

A.

[Java EE: Helen:Houston][Java ME: Jessy:Chicago, Java ME: Mark:Chicago]

B.

Java EEJava ME

C.

[Java ME: Jessy:Chicago, Java ME: Mark:Chicago][Java EE: Helen:Houston]

D.

A compilation error occurs.

Full Access
Question # 22

Given:

and the code fragment:

What is the result?

A.

A compilation error occurs at line n2.

B.

A compilation error occurs because the try block doesn’t have a catch or finally block.

C.

A compilation error occurs at line n1.

D.

The program compiles successfully.

Full Access
Question # 23

Given:

interface Doable {

public void doSomething (String s);

}

Which two class definitions compile? (Choose two.)

A.

public abstract class Task implements Doable {public void doSomethingElse(String s) { }}

B.

public abstract class Work implements Doable {public abstract void doSomething(String s) { }public void doYourThing(Boolean b) { }}

C.

public class Job implements Doable {public void doSomething(Integer i) { }}

D.

public class Action implements Doable {public void doSomething(Integer i) { }public String doThis(Integer j) { }}

E.

public class Do implements Doable {public void doSomething(Integer i) { }public void doSomething(String s) { }public void doThat (String s) { }}

Full Access
Question # 24

Given:

public class product {

int id; int price;

public Product (int id, int price) {

this.id = id;

this.price = price;

}

public String toString() { return id + “:” + price; }

}

and the code fragment:

List products = Arrays.asList(new Product(1, 10),

new Product (2, 30),

new Product (2, 30));

Product p = products.stream().reduce(new Product (4, 0), (p1, p2) -> {

p1.price+=p2.price;

return new Product (p1.id, p1.price);});

products.add(p);

products.stream().parallel()

.reduce((p1, p2) - > p1.price > p2.price ? p1 : p2)

.ifPresent(System.out: :println);

What is the result?

A.

2 : 30

B.

4 : 0

C.

4 : 70

D.

4 : 602 : 303 : 201 : 10

E.

The program prints nothing.

Full Access
Go to page: