Inheritance
11.What is the primary advantage of using inheritance in large-scale software applications?
-
A. ) It reduces execution time of the program
-
B. It improves code reusability and maintainability
-
C. It eliminates the need for object creation
-
D. It ensures that all methods are executed in the same order
It improves code reusability and maintainability
It improves code reusability and maintainability
12.Which of the following best describes how Java prevents multiple inheritance?
-
A. Java does not allow a class to inherit from more than one class
-
B. Java allows multiple inheritance only through abstract classes
-
C. Java allows multiple inheritance only through interfaces
-
D. Java completely supports multiple inheritance like C++
Java allows multiple inheritance only through interfaces
Java allows multiple inheritance only through interfaces
13.Which of the following is NOT a reason to use inheritance in Java?
-
A. To achieve code reusability
-
B. To allow child classes to override private methods of the parent class
-
C. To establish a relationship between general and specific classes
-
D. To improve maintainability by reducing redundancy
To allow child classes to override private methods of the parent class
To allow child classes to override private methods of the parent class
14.Why does Java enforce single inheritance for classes but allow multiple inheritance through interfaces?
-
A. To avoid ambiguity in method resolution
-
B. Because Java does not support virtual inheritance
-
C. To ensure constructors are not inherited
-
D. To limit the number of parent classes
To avoid ambiguity in method resolution
To avoid ambiguity in method resolution
15.If a superclass has a final method, what will happen if a subclass attempts to override it?
-
A. The program will compile successfully
-
B. The subclass method will override it as usual
-
C. A compilation error will occur
-
D. The superclass method will be ignored
A compilation error will occur
A compilation error will occur