250+ TOP MCQs on Inheritance – 2 and Answers

This set of Java Interview Questions and Answers for freshers on “Inheritance – 2”.

1. What is not type of inheritance?
a) Single inheritance
b) Double inheritance
c) Hierarchical inheritance
d) Multiple inheritance

Answer: b
Clarification: Inheritance is way of acquiring attributes and methods of parent class. Java supports hierarchical inheritance directly.

2. Using which of the following, multiple inheritance in Java can be implemented?
a) Interfaces
b) Multithreading
c) Protected methods
d) Private methods

Answer: a
Clarification: Multiple inheritance in java is implemented using interfaces. Multiple interfaces can be implemented by a class.

3. All classes in Java are inherited from which class?
a) java.lang.class
b) java.class.inherited
c) java.class.object
d) java.lang.Object

Answer: d
Clarification: All classes in java are inherited from Object class. Interfaces are not inherited from Object Class.

4. In order to restrict a variable of a class from inheriting to subclass, how variable should be declared?
a) Protected
b) Private
c) Public
d) Static

Answer: b
Clarification: By declaring variable private, the variable will not be available in inherited to subclass.

5. If super class and subclass have same variable name, which keyword should be used to use super class?
a) super
b) this
c) upper
d) classname

Answer: a
Clarification: Super keyword is used to access hidden super class variable in subclass.

6. Static members are not inherited to subclass.
a) True
b) False

Answer: b
Clarification: Static members are also inherited to subclasses.

7. Which of the following is used for implementing inheritance through an interface?
a) inherited
b) using
c) extends
d) implements

Answer: d
Clarification: Interface is implemented using implements keyword. A concrete class must implement all the methods of an interface, else it must be declared abstract.

8. Which of the following is used for implementing inheritance through class?
a) inherited
b) using
c) extends
d) implements

Answer: c
Clarification: Class can be extended using extends keyword. One class can extend only one class. A final class cannot be extended.

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.
a) Runtime error
b) Compile time error
c) Code runs successfully
d) First called method is executed successfully

Answer: b
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.

10. Does Java support multiple level inheritance?
a) True
b) False

Answer: a
Clarification: Java supports multiple level inheritance through implementing multiple interfaces.

Java for Interviews, here is complete set on Multiple Choice Questions and Answers on Java.

contest

Leave a Reply

Your email address will not be published. Required fields are marked *