Given the code fragment:
What is the result?
A. Compilation fails.
B. Hi removed
C. An UnsupportedOperationException is thrown at runtime.
D. The program compiles, but it prints nothing.
Given the code fragment:
What is the result?
A. Compilation fails.
B. Hi removed
C. An UnsupportedOperationException is thrown at runtime.
D. The program compiles, but it prints nothing.
If syntax errors fixed in arr and arrList declarations, compilation error arises due to not reachable “s” in code block of if statement
public static void main(String[] args) {
String[] arr = {“Hi”, “How”, “Are”, “You”};
List arrList = new ArrayList(Arrays.asList(arr));
if(arrList.removeIf(s -> { return s.length() <= 2;})){
System.out.println(s+ " removed");
};
}
A:
Test17.java:3: error: ‘)’ expected
String [] arr = (“Hi”, “How”, “Are”, “You”);
^
………..
Test17.java:5: error: ‘;’ expected
if (arrList.removeIf((string s) -> (return s.length() <=2 ))) {
^
Test17.java:9: error: class, interface, or enum expected
}
^
14 errors
Answer A:
Due to syntax errors.