ProgrammingVery hardProduct-company MCQ pattern
What is printed?
What is printed?
Integer a = 127; Integer b = 127; Integer c = 200; Integer d = 200; System.out.println((a == b) + " " + (c == d));
- A. true true
- B. true false
- C. false false
- D. false true
Correct answer: B. true false
Java caches boxed Integer objects for values from -128 to 127 (the Integer cache); autoboxing 127 twice returns the same cached object, so a==b is true. 200 is outside the cache range, so each autoboxing creates a distinct object, making c==d false — a classic autoboxing identity trap.
More OOP with C++ and Java questions
- What is printed? java class Base { public void show() { System.out.print("Base "); } } class Derived extends Base { protected void show()…
- What is printed? java class Base { void greet(Object o) { System.out.print("Object "); } } class Derived extends Base { void greet(String…
- What is printed? java class Base { static void show() { System.out.print("Base.static "); } } class Derived extends Base { static void…
- What is printed? java class Base { protected int code = 1; } class Derived extends Base { int code = 2; } // in main: Base b = new…
- What is printed? java class Vehicle { void start() { System.out.print("Vehicle starts "); } } interface Electric { default void start() {…
- What is printed? java interface Counter { int next(); private int helper() { return 100; } default int nextPlusHelper() { return next() +…