Q: When a Class inherits two superclasses (not in Java), it is called ____ inheritance.
Solution: Multiple Inheritance
Q: A Subclass can become a Superclass to another class extending from it in Java. State TRUE or FALSE.
Solution: Yes, true.
Q: Find Superclass and Subclass in the below Java code snippet? class B { void show(){} } class A { void hide(){} }
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(){} }
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?
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?
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 ____.
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.
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 |