Inheritance
16.If a superclass has a private method and a subclass defines a method with the same name, what happens?
-
A. The subclass method overrides the private method
-
B. The subclass method has no connection to the superclass method
-
C. The subclass method will cause a compilation error
-
D. The superclass method is automatically called
The subclass method has no connection to the superclass method
The subclass method has no connection to the superclass method
17.What is the effect of defining a subclass constructor without calling super ()?
-
A. The compiler inserts a call to the no-argument constructor of the superclass
-
B. The program crashes at runtime
-
C. The subclass constructor will fail to compile
-
D. The superclass constructor is ignored
The compiler inserts a call to the no-argument constructor of the superclass
The compiler inserts a call to the no-argument constructor of the superclass
18.In Java, why can a child class have more specialized methods than its parent class?
-
A. Because Java allows method overloading
-
B. Because the child class can have additional behaviors beyond the parent class
-
C. Because Java supports static methods in subclasses
-
D. Because inheritance only allows method overriding, not overloading
Because the child class can have additional behaviors beyond the parent class
Because the child class can have additional behaviors beyond the parent class
19.If a superclass method is protected, how can it be accessed in a subclass?
-
A. Only through an instance of the subclass
-
B. Only if it is overridden in the subclass
-
C. Directly within the subclass
-
D. It cannot be accessed in the subclass
Directly within the subclass
Directly within the subclass
20.What will happen if a class marked as final tries to extend another class?
-
A. The compiler will throw an error
-
B. The class will override all superclass methods
-
C. The final class will inherit but cannot override methods
-
D. The final class will not inherit static methods
The compiler will throw an error
The compiler will throw an error