Question
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();
}
}
a.
2 2
b.
3 3
c.
Runtime Error
d.
Compilation Error
Posted under Java Programming
Engage with the Community - Add Your Comment
Confused About the Answer? Ask for Details Here.
Know the Explanation? Add it Here.
Q. What is the output of this program?
Similar Questions
Discover Related MCQs
Q. Which of this keyword must be used to inherit a class?
View solution
Q. A class member declared protected becomes a member of subclass of which type?
View solution
Q. Which of these is correct way of inheriting class A by class B?
View solution
Q. What is not type of inheritance?
View solution
Q. Using which of the following, multiple inheritance in Java can be implemented?
View solution
Q. All classes in Java are inherited from which class?
View solution
Q. In order to restrict a variable of a class from inheriting to subclass, how variable should be declared?
View solution
Q. If super class and subclass have same variable name, which keyword should be used to use super class?
View solution
Q. Static members are not inherited to subclass.
View solution
Q. Which of the following is used for implementing inheritance through an interface?
View solution
Q. Which of the following is used for implementing inheritance through class?
View solution
Q. What would be the result if a class extends two interfaces and both have a method with same name and signature?
View solution
Q. Does Java support multiple level inheritance?
View solution
Q. Which of this keyword can be used in a subclass to call the constructor of superclass?
View solution
Q. What is the process of defining a method in a subclass having same name & type signature as a method in its superclass?
View solution
Q. Which of these keywords can be used to prevent Method overriding?
View solution
Q. Which of these is correct way of calling a constructor having no parameters, of superclass A by subclass B?
View solution
Q. Which of these is supported by method overriding in Java?
View solution
Q. What are the features of an Object Oriented Programming (OOPs)?
View solution
Q. What are the features reused using Inheritance in Java?
View solution
Suggested Topics
Are you eager to expand your knowledge beyond Java Programming? We've curated a selection of related categories that you might find intriguing.
Click on the categories below to discover a wealth of MCQs and enrich your understanding of Computer Science. Happy exploring!