ProgrammingHardWipro NLTH · Capgemini
What is printed?
What is printed?
String s = "a";
s.concat("b");
s += "c";
System.out.print(s);- A. ac
- B. abc
- C. a
- D. ab
Correct answer: A. ac
Strings are immutable: concat's result was discarded, so only the += c took effect.
More OOP with C++ and Java questions
- What is printed? (C++, assume <iostream> and using namespace std) cpp struct B { void f(int) { cout << "Bi"; } }; struct D : B { void…
- What is printed? java class A { static { System.out.print("S"); } { System.out.print("I"); } A() { System.out.print("C"); } } // in main…
- What is printed? (C++, assume <iostream> and using namespace std) cpp class B { public: void call() { f(); } private: virtual void f() {…
- What is printed? java static void f(long x) { System.out.print("long"); } static void f(Integer x) { System.out.print("Integer"); } static…
- What is printed? java Object o = true ? 1 : 2.0; System.out.print(o);
- What is printed? (C++, assume <iostream> and using namespace std) cpp struct S { void f() { cout << "n"; } void f() const { cout << "c"; }…