Test Series - java

Test Number 61/64

Q: When a Class inherits two superclasses (not in Java), it is called ____ inheritance.
A. Multilevel inheritance
B. Single Inheritance
C. Multiple Inheritance
D. None
Solution: Multiple Inheritance
Q: A Subclass can become a Superclass to another class extending from it in Java. State TRUE or FALSE.
A. TRUE
B. FALSE
C. -
D. -
Solution: Yes, true.
Q: Find Superclass and Subclass in the below Java code snippet?
class B
{
  void show(){}
}
class A
{
  void hide(){}
}
A. B is superclass and A is subclass.
B. A is superclass and B is a subclass.
C. There is no superclass or subclass present.
D. None
Solution: As there is no use of the "extends" keyword, inheritance does not come into the picture. So, there is no superclass or subclass present in the above example.
Q: Find Superclass and Subclass in the below Java program?
class Liquid
{
  void pour(){}
}
class Juice extends Liquid
{
  void filter(){}
}
A. The Liquid is a superclass and Juice is a subclass.
B. The Liquid is a Subclass and Juice is a Superclass.
C. There is no superclass or subclass
D. None
Solution: As the Juice class is extending from the Liquid class, Juice is a subclass and Liquid is a superclass. Simply put, the class before the "extends" keyword is always a Subclass.
Q: Which is the keyword used to implement inheritance in Java?
A. extends
B. implements
C. instanceof
D. None
Solution: The keyword "extends" tells the compiler that the class on the left side is subclassing the class on the right side.
Q: Can you call it a full-fledged inheritance of using ABSTRACT classes and INTERFACES in Java?
A. NO
B. YES
C. -
D. -
Solution: No. Abstract classes and Interfaces do not define a class completely. So, it is not called a full-fledged inheritance of using those.
Q: To control inheritance to different classes and levels, Java provides ____.
A. Return types like the void, int, float, double and other object types
B. Static keyword
C. Access modifiers like default, public, protected, private
D. None
Solution: Access modifiers like default (not a keyword), public, protected and private changed the visibility of a method, variable or a class. Even the keyword "package" also allows grouping of classes and control inheritance levels to some extent.
Q: To stop or block inheriting a given class, the ___ keyword is used before the class.
A. static
B. private
C.  final
D. none of the above
Solution: You can not subclass a class that is marked FINAL.


final class CLASS_NAME //Can not subclass
{

}
class SUBCLASS extends CLASS_NAME //ERROR
{

}

You Have Score    /8