Question 95Asked in BEL PE Computer Science, 20 Dec 2025 (5:00 PM)

Consider the following Java code: class Parent {

Consider the following Java code: class Parent { int x = 10; void show() { System.out.println("Parent: " + x); } } class Child extends Parent { int x = 20; void show() { System.out.println("Child: " + x); } } public class Test { public static void main(String[] args) { Parent obj = new Child(); System.out.println(obj.x); obj.show(); } } What will be the output of this program?
  1. A10 Parent: 10
  2. B20 Child: 20
  3. C20 Parent: 10
  4. D10 Child: 20
Show answerHide answer

Correct answer: (D) 10 Child: 20

From BEL PE Computer Science PYQ, 20 Dec 2025 (5:00 PM)

This is question 95 of BEL PE Computer Science PYQ, 20 Dec 2025 (5:00 PM). See all questions of this paper with answers, or attempt the paper as a timed online test to get your score and all-India rank.