339). What is not type of inheritance?
[A]Single inheritance
[B]Double inheritance
[C]Hierarchical inheritance
[D] Multiple inheritance
Show Answer
Correct Answer: Double inheritance
Notes:
Answer: b
Explanation: Inheritance is way of acquiring attributes and methods of parent class. Java supports hierarchical inheritance directly.
340). Using which of the following, multiple inheritance in Java can be implemented?
[A]Interfaces
[B]Multithreading
[C]Protected methods
[D]Private methods
Show Answer
Correct Answer: Interfaces
Notes:
Answer: a
Explanation: Multiple inheritance in java is implemented using interfaces. Multiple interfaces can be implemented by a class.
341). 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
Show Answer
Correct Answer: java.lang.Object
Notes:
Answer: d
Explanation: All classes in java are inherited from Object class. Interfaces are not inherited from Object Class.
342). 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
Show Answer
Correct Answer: Private
Notes:
Answer: b
Explanation: By declaring variable private, the variable will not be available in inherited to subclass.
343). 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
Show Answer
Correct Answer: super
Notes:
Answer: a
Explanation: Super keyword is used to access hidden super class variable in subclass.
344). Static members are not inherited to subclass.
[A]True
[B]False
[C]none
[D]none
Show Answer
Correct Answer: False
Notes:
Answer: b
Explanation: Static members are also inherited to subclasses.
345). Which of the following is used for implementing inheritance through an interface?
[A]inherited
[B]using
[C]extends
[D]implements
Show Answer
Correct Answer: implements
Notes:
Answer: d
Explanation: Interface is implemented using implements keyword. A concrete class must implement all the methods of an interface, else it must be declared abstract.
346). Which of the following is used for implementing inheritance through class?
[A]inherited
[B]using
[C]extends
[D]implements
Show Answer
Correct Answer: extends
Notes:
Answer: c
Explanation: Class can be extended using extends keyword. One class can extend only one class. A final class cannot be extended.
347). 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
Show Answer
Correct Answer: Compile time error
Notes:
Answer: b
Explanation: In case of such conflict, compiler will not be able to link a method call due to ambiguity. It will throw compile time error.
348). Does Java support multiple level inheritance?
[A]True
[B]False
[C]none
[D]none
Show Answer
Correct Answer: True
Notes:
Answer: a
Explanation: Java supports multiple level inheritance through implementing multiple interfaces.