Looking for *Програмування на Jаvа test answers and solutions? Browse our comprehensive collection of verified answers for *Програмування на Jаvа at dl.nure.ua.
Get instant access to accurate answers and detailed explanations for your course questions. Our community-driven platform helps students succeed!
Which of the following lines can be inserted to make the code compile? (Choose all that apply.)
class A {}
class B extends A {}
class C extends B {}
class D<C> {
// INSERT CODE HERE
}
What changes need to be made to make the following singleton pattern correct? (Choose all that apply.)
public class CheetahManager {
public static CheetahManager cheetahManager;
private CheetahManager() {}
public static CheetahManager getCheetahManager() {
if(cheetahManager == null) {
cheetahManager = new CheetahManager();
}
return cheetahManager;
}
}
Assuming MyTask is an abstract class that implements the ForkJoinTask interface, what statements about the following code are true? (Choose all that apply.)
import java.util.concurrent.*;
public class FindMin extends MyTask {
private Integer[] elements;
private int a;
private int b;
public FindMin(Integer[] elements, int a, int b) {
this.elements = elements;
this.a = a;
this.b = b;
}
public Integer compute() {
if ((b—a) < 2)
return Math.min(elements[a], elements[b]);
else {
int m = a + ((b—a) / 2);
System.out.println(a + "," + m + "," + b);
MyTask t1 = new FindMin(elements, a, m);
int result = t1.fork().join();
return Math.min(new FindMin(elements, m, b).compute(), result);
}
}
public static void main(String[] args) throws InterruptedException,
ExecutionException {
Integer[] elements = new Integer[] { 8, -3, 2, -54 };
MyTask task = new FindMin(elements, 0, elements.length—1);
ForkJoinPool pool = new ForkJoinPool(1);
Integer sum = pool.invoke(task);
System.out.println("Min: " + sum);
}
}
What is the output of the following code?
1: public class ArithmeticSample {
2: public static void main(String[] args) {
3: int x = 5 * 4 % 3;
4: System.out.println(x);
5: }}
Which of the following are valid Callable expressions? (Choose all that apply.)
Which of the following are true? (Choose all that apply)
public class Bunny {
public static void main(String[] args) {
Bunny bun = new Bunny();
} }
Which three scenarios would best benefit from using a singleton pattern? (Choose all three.)
What is output by the following code? (Choose all that apply)
1: public class Fish {
2: public static void main(String[] args) {
3: int numFish = 4;
4: String fishType = "tuna";
5: String anotherFish = numFish + 1;
6: System.out.println(anotherFish + " " + fishType);
7: System.out.println(numFish + " " + 1);
8: } }
What changes need to be made to make the following immutable object pattern correct? (Choose all that apply.)
import java.util.List;
public class Seal {
String name;
private final List<Seal> friends;
public Seal(String name, List<Seal> friends) {
this.name = name;
this.friends = friends;
}
public String getName() { return name; }
public List<Seal> getFriends() { return friends; }
}
None; the immutable object pattern is properly implemented.
What is the output of the following program?
1: public class WaterBottle {
2: private String brand;
3: private boolean empty;
4: public static void main(String[] args) {
5: WaterBottle wb = new WaterBottle();
6: System.out.print("Empty = " + wb.empty);
7: System.out.print(", Brand = " + wb.brand);
8: } }