G.11 final
Methods and Classes
We saw in Sections D.3 and D.10 that variables can be declared final
to indicate that they cannot be modified after they’re initialized—such variables represent constant values. It’s also possible to declare methods, method parameters and classes with the final
modifier.
Final Methods Cannot Be Overridden
A final
method in a superclass cannot be overridden in a subclass—this guarantees that the final
method implementation will be used by all direct and indirect subclasses in the hierarchy. Methods that are declared private
are implicitly final
, because it’s not possible to override them in a subclass. Methods that are declared static
are also implicitly final
. A final
method’s declaration can never change, so ...
Get Android How to Program, 3/e now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.