
Asked in LTIMindtree
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!
Add answer anonymously...
Top Automation Engineer Interview Questions Asked at LTIMindtree
Q. How do you implement custom assertions in Selenium?
Q. Given an array of integers, sort the array in ascending order using the Bubble S...read more
Q. What is the difference between final, finally, and finalize?
Interview Questions Asked to Automation Engineer at Other Companies
Top Skill-Based Questions for LTIMindtree Automation Engineer
Software Testing Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
Algorithms Interview Questions and Answers
250 Questions
Software Development Interview Questions and Answers
250 Questions
Automation Interview Questions and Answers
250 Questions
PLC Interview Questions and Answers
100 Questions
Stay ahead in your career. Get AmbitionBox app


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
AmbitionBox Awards
Get AmbitionBox app

