This set of Java Interview Questions and Answers for freshers on “Inheritance – 2”.
1. What is not type of inheritance? Answer: b 2. Using which of the following, multiple inheritance in Java can be implemented? Answer: a 3. All classes in Java are inherited from which class? Answer: d 4. In order to restrict a variable of a class from inheriting to subclass, how variable should be declared? Answer: b 5. If super class and subclass have same variable name, which keyword should be used to use super class? Answer: a 6. Static members are not inherited to subclass. Answer: b 7. Which of the following is used for implementing inheritance through an interface? Answer: d 8. Which of the following is used for implementing inheritance through class? Answer: c 9. What would be the result if a class extends two interfaces and both have a method with same name and signature? Lets assume that the class is not implementing that method. Answer: b 10. Does Java support multiple level inheritance? Answer: a Java for Interviews, here is complete set on Multiple Choice Questions and Answers on Java.
a) Single inheritance
b) Double inheritance
c) Hierarchical inheritance
d) Multiple inheritance
Clarification: Inheritance is way of acquiring attributes and methods of parent class. Java supports hierarchical inheritance directly.
a) Interfaces
b) Multithreading
c) Protected methods
d) Private methods
Clarification: Multiple inheritance in java is implemented using interfaces. Multiple interfaces can be implemented by a class.
a) java.lang.class
b) java.class.inherited
c) java.class.object
d) java.lang.Object
Clarification: All classes in java are inherited from Object class. Interfaces are not inherited from Object Class.
a) Protected
b) Private
c) Public
d) Static
Clarification: By declaring variable private, the variable will not be available in inherited to subclass.
a) super
b) this
c) upper
d) classname
Clarification: Super keyword is used to access hidden super class variable in subclass.
a) True
b) False
Clarification: Static members are also inherited to subclasses.
a) inherited
b) using
c) extends
d) implements
Clarification: Interface is implemented using implements keyword. A concrete class must implement all the methods of an interface, else it must be declared abstract.
a) inherited
b) using
c) extends
d) implements
Clarification: Class can be extended using extends keyword. One class can extend only one class. A final class cannot be extended.
a) Runtime error
b) Compile time error
c) Code runs successfully
d) First called method is executed successfully
Clarification: In case of such conflict, compiler will not be able to link a method call due to ambiguity. It will throw compile time error.
a) True
b) False
Clarification: Java supports multiple level inheritance through implementing multiple interfaces.