ProgrammingModerateTCS NQT · Infosys pattern
What is printed?
What is printed?
System.out.print(1 + 2 + "3" + 4 + 5);
- A. 3345
- B. 339
- C. 15
- D. 12345
Correct answer: A. 3345
+ groups left to right: 1 + 2 = 3 (numbers), then 3 + "3" = "33" (a String), and from then on every + concatenates: "334", "3345".
More OOP with C++ and Java questions
- What is printed? java // static methods of the main class: static void change(StringBuilder sb) { sb.append("X"); sb = new…
- What is printed? java List<Integer> l = new ArrayList<>(List.of(1, 2, 3)); l.remove(1); System.out.print(l + " ")…
- What is printed? java List<Integer> list = new ArrayList<>(List.of(1, 2, 3)); for (Integer i : list) if (i == 2) list.remove(i)…
- What happens with this C++ code? cpp void f(int a, int b = 0) { cout << "two"; } void f(int a) { cout << "one"; } int main() { f(5); }
- What is printed? cpp struct Base { virtual void show() { cout << "Base "; } }; struct Derived : Base { void show() override { cout <<…
- What is printed? cpp class Base { public: Base() { hello(); } virtual void hello() { cout << "B"; } }; class Derived : public Base {…