ProgrammingVery hardTCS NQT · Wipro NLTH
What is printed?
What is printed?
String a = "ja" + "va"; String b = "java"; String c = "ja"; String d = c + "va"; System.out.print((a == b) + "," + (d == b));
- A. true,false
- B. true,true
- C. false,false
- D. false,true
Correct answer: A. true,false
"ja" + "va" is a compile-time constant and is interned, but c + "va" is built at run time as a new String.
More OOP with C++ and Java questions
- What is printed? (C++, assume <iostream> and using namespace std) cpp struct A { A() { cout << "A"; } }; struct B : virtual A { }; struct…
- What is printed? (C++17; assume <iostream>, <string>, <vector> and using namespace std) cpp struct A { virtual void f(int x = 1) { cout <<…
- What is printed? (C++17; assume <iostream>, <string>, <vector> and using namespace std) cpp struct A { virtual void p() { cout << "A"; }…
- What is printed? (C++17; assume <iostream>, <string>, <vector> and using namespace std) cpp struct X { string n; X(const char s) : n(s) {…
- What is printed? (C++17; assume <iostream>, <string>, <vector> and using namespace std) cpp struct A { A() { f(); } virtual void f() {…
- What is printed? (C++17; assume <iostream>, <string>, <vector> and using namespace std) cpp struct A { virtual ~A() { f(); } virtual void…