in Java recategorized by
1 vote
1 vote

Method over-riding can be prevented by using final as a modifier at ______.

  1. The start of the class.
  2. The start of method declaration.
  3. The start of derived class.
  4. The start of the method declaration in the derived class.
in Java recategorized by

2 Answers

0 votes
0 votes
i think option b

if it is used at the start of the class then it used to prevent  the class from being extended or subclassed not from being overridden

in order to prevent overriding,final keyword is placed at the start of the method
0 votes
0 votes

Ans: B

All methods and variables can be overridden by default in subclasses. If we wish to prevent the subclasses from overriding the members of the superclass, we can declare them as final using the keyword final as a modifier. If any attempt to override a final method in a subclass results in the compiler error. For example, in the following program, the method dataValues( ) is declared as final, it cannot be overridden in DataV2. If you attempt to do so, a compile error will result.

reference :

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true