Bird
0
0

You want to prevent a method from being overridden but allow the class to be inherited. Which is the correct approach?

hard📝 Application Q8 of 15
Java - Inheritance

You want to prevent a method from being overridden but allow the class to be inherited. Which is the correct approach?

ADeclare the method as private
BDeclare the method as final
CDeclare the method as static
DDeclare the class as final
Step-by-Step Solution
Solution:
  1. Step 1: Understand final method usage

    Declaring a method final prevents overriding but allows class inheritance.
  2. Step 2: Analyze other options

    Declaring class final prevents inheritance; static methods are hidden, not overridden; private methods are not inherited.
  3. Final Answer:

    Declare the method as final to prevent overriding -> Option B
  4. Quick Check:

    final method blocks override, class inheritance allowed [OK]
Quick Trick: Use final on method to block override, keep class inheritable [OK]
Common Mistakes:
  • Making class final instead
  • Confusing static with final
  • Using private which hides method

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes