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...
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
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

