ProgrammingVery hardWipro Elite · TCS NQT Prime
What is printed?
What is printed?
byte b = 10; b += 120; System.out.print(b + " " + (b >>> 1));
- A. 130 65
- B. -126 -63
- C. -126 126
- D. -126 2147483585
Correct answer: D. -126 2147483585
b += 120 casts 130 back to byte, giving -126; b >>> 1 promotes to int 0xFFFFFF82, and the unsigned shift gives 0x7FFFFFC1 = 2147483585.
More OOP with C++ and Java questions
- What is printed? java try { try { throw new Exception("1"); } finally { throw new RuntimeException("2"); } } catch (Exception e) {…
- What is printed? java class R implements AutoCloseable { String n; R(String n) { this.n = n; System.out.print("o" + n); } public void…
- What is printed? java class A {} class B extends A {} static void f(A a) { System.out.print("A"); } static void f(B b) {…
- What is printed? java class P { void f(Object o) { System.out.print("PO"); } } class C extends P { void f(String s) {…
- What happens? java static void f(String s) { System.out.print("S"); } static void f(Integer i) { System.out.print("I"); } // main: f(null);
- What is printed? java System.out.print('a' + 'b' + "c" + 'a' + 'b');