MCQ
Single Best Answer
Not Set
QWhat is the output of this program?
class A
{
public int i;
private int j;
}
class B extends A
{
void display()
{
super.j = super.i + 1;
System.out.println(super.i + " " + super.j);
}
}
class inheritance
{
public static void main(String args[])
{
B obj = new B();
obj.i=1;
obj.j=2;
obj.display();
}
}
ID: #2248
Inheritance in Java MCQ
17,287 views
Question Info
#2248Q ID
Not SetDifficulty
Inheritance in Java MCQTopic
Your Answer
Choose the Best Option
Click any option to instantly check if you're correct.
Correct Answer: Option D
Explanation
Class contains a private member variable j, this cannot be inherited by subclass B and does not have access to it.
output:
$ javac inheritance.java
Exception in thread “main” java.lang.Error: Unresolved compilation problem:
The field A.j is not visible
Continue Practice
Share
Share This Question
Challenge a friend or share with your study group.
More from This Topic