Given the code fragment:
Which is the valid definition of the Course enum?
Correct Answer:A
Which two are elements of a singleton class? (Choose two.)
Correct Answer:BD
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?
Correct Answer:C
Given the code fragment:
List
int i = 0;
boolean result = s.contains (“pen”);
System.out.print(i++) + “:”); return result;
};
str.stream()
.filter(test)
.findFirst()
.i fPresent(System.out ::print); What is the result?
Correct Answer:A
Given:
and the code fragment:
What is the result?
Correct Answer:B
Given: Book.java:
public class Book {
private String read(String bname) { return “Read” + bname }
}
EBook.java:
public class EBook extends Book {
public class String read (String url) { return “View” + url }
}
Test.java:
public class Test {
public static void main (String[] args) { Book b1 = new Book();
b1.read(“Java Programing”); Book b2 = new EBook();
b2.read(“http://ebook.com/ebook”);
}
}
What is the result?
Correct Answer:D