ProgrammingHardProduct-company placement · GATE CS
What is printed?
What is printed?
char c = 'a';
c += 1;
System.out.print(c + 1);
System.out.print(" " + c + 1);- A. c b1
- B. 99 c
- C. 99 b1
- D. b1 b1
Correct answer: C. 99 b1
c += 1 compiles because compound assignment casts back to char, so c is 'b'. c + 1 is int arithmetic, 98 + 1 = 99. In " " + c + 1 the left operand is a String, so concatenation runs left to right: " b" then " b1".
More OOP with C++ and Java questions
- Which statement about this code is correct? java Object[] arr = new String[2]; // L1 arr[0] = "a"; // L2 arr[1] = Integer.valueOf(1); //…
- What is printed? java int i = 5; i = i++ + ++i; System.out.print(i);
- What is printed? java class A { Object get() { return "A"; } void set(String s) { System.out.print("A.set "); } } class B extends A {…
- What is printed? java Long a = 1L; System.out.print(a.equals(1) + " " + a.equals(1L) + " " + (a == 1));
- What is printed? cpp struct B { B() { f(); } virtual ~B() { f(); } virtual void f() { cout << "B"; } }; struct D : B { D() { f(); } ~D() {…
- What is printed? cpp struct M { int id; M(int i) : id(i) { cout << "M" << id; } ~M() { cout << "m" << id; } }; struct B { B() { cout <<…