Question

What is the output of the following Java code?     class A {         int x = 10;         void show() { System.out.println("A: " +
x); }     }     class B extends A {         int x = 20;         void show() { System.out.println("B: " +
x); }     }     public class Test {         public static void main(String[] args) {             A obj = new B();             System.out.println(obj.x);             obj.show();         }     }

A 10 A: 10
B 20 B: 20
C 10 B: 20
D 20 A: 10
E Compilation error
Practice Next

Hey! Ask a query

🎓
Think You're Ready for RBI Grade B?
RBI Grade B 2026 Phase 1 Memory Based Paper
  • 200 Questions with Detailed Solutions
  • Section-wise Coverage (GA, English, Quant & Reasoning)