ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
Set<String> t = new TreeSet<>(List.of("apple", "Banana", "cherry"));
System.out.print(t);- A. [apple, Banana, cherry]
- B. [cherry, Banana, apple]
- C. [apple, cherry, Banana]
- D. [Banana, apple, cherry]
Correct answer: D. [Banana, apple, cherry]
TreeSet sorts by String's natural order, which compares character codes. Uppercase letters (65–90) come before lowercase (97–122), so Banana sorts first.
More OOP with C++ and Java questions
- What happens when this Java code is compiled? java class P { P(int x) { } } class C extends P { C() { } }
- What is printed? java // static methods of the main class: static void f(int... a) { System.out.print("V"); } static void f(int a, int b)…
- Which member function fails to compile? cpp class C { int a = 0; mutable int hits = 0; public: int get() const { hits++; return a; } void…
- Which C++ operator can be overloaded only as a non-static member function, never as a free function?
- What is printed? java List<Integer> l = Arrays.asList(1, 2, 3); try { l.set(0, 9); System.out.print(l); l.add(4); } catch…
- What is printed? java Map<String, Integer> m = new HashMap<>(); System.out.print(m.put("a", 1)); System.out.print(" " + m.put("a", 2))…