Given:
public class Counter {
public static void main (String[ ] args) {
int a = 10;
int b = -1;
assert (b >=1) : "Invalid Denominator";
int = a / b;
System.out.println (c);
}
}
What is the result of running the code with the -ea option?
A. -10
B. 0
C. An AssertionError is thrown.
D. A compilation error occurs.
Given:
class Bird {
public void fly () { System.out.print("Can fly"); }
}
class Penguin extends Bird {
public void fly () { System.out.print("Cannot fly"); }
}
and the code fragment:
class Birdie {
public static void main (String [ ] args) {
fly( ( ) -> new Bird ( ));
fly (Penguin : : new);
}
/* line n1 */
}
Which code fragment, when inserted at line n1, enables the Birdie class to compile?
A. static void fly (Consumer
B. static void fly (Consumer extends Bird> bird) bird.accept( ) fly (); } {
C. static void fly (Supplier
D. static void fly (Supplier extends Bird> bird) LOST
Given that course.txt is accessible and contains:
Course : : Java
and given the code fragment:
public static void main (String[ ] args) { int i; char c; try (FileInputStream fis = new FileInputStream (“course.txt”);
InputStreamReader isr = new InputStreamReader(fis);) {
while (isr.ready()) { //line n1
isr.skip(2);
i = isr.read ();
c = (char) i;
System.out.print(c);
} } catch (Exception e) { e.printStackTrace(); } }
What is the result?
A. ur :: va
B. ueJa
C. The program prints nothing.
D. A compilation error occurs at line n1.
Given:
interface Rideable {Car getCar (String name); }
class Car {
private String name;
public Car (String name) {
this.name = name;
}
}
Which code fragment creates an instance of Car?
A. Car auto = Car ("MyCar"): : new;
B. Car auto = Car : : new; Car vehicle = auto : : getCar("MyCar");
C. Rideable rider = Car : : new; Car vehicle = rider.getCar("MyCar");
D. Car vehicle = Rideable : : new : : getCar("MyCar");
Which statement is true about java.util.stream.Stream?
A. A stream cannot be consumed more than once.
B. The execution mode of streams can be changed during processing.
C. Streams are intended to modify the source data.
D. A parallel stream is always faster than an equivalent sequential stream.
Given the code fragment:
List
Which code fragment, when inserted at line n1, prints 10 20 15 30?
A. Stream.of(list1, list2) .flatMap(list -> list.stream()) .forEach(s -> System.out.print(s + " "));
B. Stream.of(list1, list2) .flatMap(list -> list.intStream()) .forEach(s -> System.out.print(s + " "));
C. list1.stream() .flatMap(list2.stream().flatMap(e1 -> e1.stream()) .forEach(s -> System.out.println(s + " "));
D. Stream.of(list1, list2) .flatMapToInt(list -> list.stream()) .forEach(s -> System.out.print(s + " "));
Given the code fragments:
and
What is the result?
A. France Optional[NotFound]
B. Optional [France] Optional [NotFound]
C. Optional[France] Not Found
D. France Not Found
Given:
Which two interfaces can you use to create lambda expressions? (Choose two.)
A. T
B. R C. P
D. S
E. Q
F. U
Given:
Which option fails?
A. Foo
B. Foo
C. Foo
D. Foo
Given the definition of the Emp class:
public class Emp
private String eName;
private Integer eAge;
Emp(String eN, Integer eA) {
this.eName = eN;
this.eAge = eA;
}
public Integer getEAge () {return eAge;}
public String getEName () {return eName;}
}
and code fragment:
List
Predicate
li = li.stream().filter(agVal).collect(Collectors.toList());
Stream
names.forEach(n -> System.out.print(n + " "));
What is the result?
A. Sam John Jim
B. John Jim
C. A compilation error occurs at line n1.
D. A compilation error occurs at line n2.