ProgrammingVery hardProduct-company placement · Java
What is printed?
What is printed?
System.out.print("a.b".replace(".", "x") + " " + "a.b".replaceAll(".", "x"));- A. axb axb
- B. axb xxx
- C. xxx xxx
- D. xxx axb
Correct answer: B. axb xxx
replace(CharSequence, CharSequence) works on literal text, but replaceAll interprets its first argument as a regex, where . matches any character.
More OOP with C++ and Java questions
- What is printed? java List<Integer> src = List.of(1, 2); List<Integer> dst = new ArrayList<>(5); Collections.copy(dst, src)…
- What is printed? java enum Size { S; public String toString() { return "small"; } } // in main: System.out.print(Size.S + " " +…
- What is printed? java Object o = new int[]{1}; System.out.print((o instanceof int[]) + " " + (o instanceof Object[]));
- Which line fails to compile? java class P { void run() throws java.io.IOException { } } class C extends P { @Override void run() { } } //…
- What is printed? java Map<String, Integer> m = new HashMap<>(); m.put("a", 1); m.keySet().remove("a"); System.out.print(m.size() + " ")…
- What is printed? java TreeSet<Integer> s = new TreeSet<>(List.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); SortedSet<Integer> sub = s.subSet(3, 6)…