MCQs
Both class A & B have member with same name that is j, member of class B will be called by
default if no specifier is used. I contains 1 & j contains 2, printing 1 2.
output:
$ javac Output.java
$ java Output
1 2
Keyword super is used to call constructor of class A by constructor of class B. Constructor of
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
None
output:
$ javac inheritance.java
$ java inheritance
2 3
class A & class B both contain display() method, class B inherits class A, when display() method
is called by object of class B, display() method of class B is executed rather than that of Class A.
output:
$ javac inheritance_demo.java
$ java inheritance_demo
2
private members of a class cannot be inherited by a sub class.
None.
A class member declared protected becomes private member of subclass.
whenever a subclass needs to refer to its immediate superclass, it can do so by use of the
keyword super.
None.