ProgrammingModerateWipro · Capgemini pattern
What is printed?
What is printed?
System.out.print('a' + 1);
System.out.print(" ");
System.out.print("" + 'a' + 1);- A. 98 a1
- B. a1 a1
- C. b a1
- D. 98 98
Correct answer: A. 98 a1
'a' + 1 is char + int, which is numeric addition: 97 + 1 = 98. In "" + 'a' + 1 the left operand is already a String, so each + concatenates: "a" then "a1".
More OOP with C++ and Java questions
- What is printed? cpp void f(int) { cout << "int "; } void f(double) { cout << "double "; } int main() { f('a'); f(2.5f); }
- What is printed? cpp struct A { A() { cout << "C"; } A(const A &) { cout << "K"; } ~A() { cout << "D"; } }; void f(A a) { } int main() { A…
- What is printed? cpp class A { public: static int count; A() { count++; } ~A() { count--; } }; int A::count = 0; int main() { A a, b; { A…
- Which line fails to compile? cpp struct Shape { virtual double area() = 0; }; struct Circle : Shape { }; struct Square : Shape { double…
- class D : private B { ... }; where B has public int x, protected int y and private int z. Which is correct?
- Which of these is a checked exception in Java?