What is the output of the following code? class A { int i = 10; } class B extends A { int i = 20; } public class test { public static void main(String[] args) { A a = new B(); System.out.println(a.i); } }

AnswerBot
1y

The code will output 10 because the variable i is accessed through a reference of class A.

  • When a subclass object is assigned to a superclass reference, the superclass reference can only access the sup...read more

Anonymous
author
1y
output is 10 , explaination search parent and child having same data member in java and read geeksforgeeks page.
Help your peers!
Select
Add answer anonymously...

LTIMindtree Automation Engineer interview questions & answers

An Automation Engineer was asked 9mo agoQ. How do you implement custom assertions in Selenium?
An Automation Engineer was asked 9mo agoQ. Given an array of integers, sort the array in ascending order using the Bubble S...read more
An Automation Engineer was asked Q. What is the output of the following code? class A { int i = 10; } class B extend...read more

Popular interview questions of Automation Engineer

An Automation Engineer was asked 9mo agoQ1. How do you implement custom assertions in Selenium?
An Automation Engineer was asked 9mo agoQ2. Given an array of integers, sort the array in ascending order using the Bubble S...read more
An Automation Engineer was asked Q3. What is the output of the following code? class A { int i = 10; } class B extend...read more
LTIMindtree Automation Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits