Science, asked by gulrahimrahime0, 6 months ago

To prevent any method from overriding, we declare the method as, static const final abstract none of the above

Answers

Answered by dishasha200872
2

Answer:

Every Java programmer knows that final modifier can be used to prevent method overriding in Java because there is no way someone can override final methods; but, apart from final modifier, is there any other way to prevent method overriding in Java? This was the exact question, asked to one of my friend in a recent Java interview at one of the leading Investment bank. I guess, he was lucky to get this question because he already knows those tricks and was able to answer it quickly. When he told me about his experience, I didn't understand why someone ask this question? What is the purpose? What they were trying to find out? I can understand if they have asked what's the best way to prevent method overriding in Java, or what is the risk of overriding? Anyway, It gives me an opportunity to recap some of the other technique (syntactically) to prevent a method from being overridden and write this blog post to share some mystery tricks from Java world. Some of you might be aware of those non obvious way to prevent method overriding, but if you don't, here is your opportunity to learn.

Explanation:

Mark me as brainliest if helpful

Answered by Jasleen0599
1

Final

To prevent any method from overriding, we declare the method as Final

  • When declaring a method, add the modifier final at the beginning to prevent it from being overridden. Methods marked as final are incompatible with overriding.
  • A method may be designated as final; once final is declared, it cannot be overridden. Therefore, a final method from a subclass cannot be changed. The major goal of making a method final would be to prevent any outsiders from changing the method's content.
  • If a method cannot be overridden by subclasses, it is indicated by the final keyword in the method definition. This is done by the Object class, which has a few final methods.
  • By placing the Final keyword before the method name, we can declare Java methods as Final Methods. It is not possible to override the method with the final keyword in the subclasses. The Final Method is used to declare methods whose definitions cannot be modified by an extender's child or subclass.

#SPJ2

Similar questions