Welcome to your Java Test 6 – High Level
1. What does this code print?
interface A { default void greet() { System.out.println("Hello from A"); } } interface B { default void greet() { System.out.println("Hello from B"); } } class C implements A, B { public void greet() { A.super.greet(); } }
2. What is the output of this code?
List list = Arrays.asList(1, 2, 3); list.set(1, 10); System.out.println(list);
3. What is the output of this code?
try { int a = 5 / 0; } catch (ArithmeticException e) { System.out.println("Error"); }
4. What is printed by this code?
String s = null; System.out.println(s == null ? "is null" : s.toString());
5. Which of the following classes is immutable?
6. What will this code print?
String a = "abc"; String b = "ab" + "c"; System.out.println(a == b);
7. Which method is used to safely compare two objects in Java (even if one is null)?
8. What will be the result of this code?
String s = "hello"; System.out.println(s.replace("l", ""));
9. What does this print?
int[] arr = new int[3]; System.out.println(arr[1]);
10. Which statement is true about Java memory management?