ProgrammingModerateTCS NQT · Infosys pattern
What is printed?
What is printed?
String s = "ab";
s.concat("cd");
s.toUpperCase();
System.out.print(s);- A. abcd
- B. ABCD
- C. ab
- D. AB
Correct answer: C. ab
Strings are immutable: concat and toUpperCase return new strings, and both results are thrown away because they are not assigned. s still refers to "ab".
More OOP with C++ and Java questions
- Which pairing is correct?
- Which of these operators cannot be overloaded in C++?
- A variable declared inside a Java interface is implicitly:
- What is printed? cpp class A { public: A() { cout << "A"; } ~A() { cout << "a"; } }; class B : public A { public: B() { cout << "B"; }…
- What is printed? java class C { static int n = 0; C() { n++; } } // in main: for (int i = 0; i < 3; i++) new C(); C c = new C()…
- In Java, final applied to a class, a method and a variable means, respectively: