Section 10.7 final Methods and Classes

• A method that’s declared final (p. 419) in a superclass cannot be overridden in a subclass.

• Methods declared private are implicitly final, because you can’t override them in a subclass.

• Methods that are declared static are implicitly final.

• A final method’s declaration can never change, so all subclasses use the same implementation, and calls to final methods are resolved at compile time—this is known as static binding (p. 420).

• The compiler can optimize programs by removing calls to final methods and inlining their expanded code at each method-call location.

• A class that’s declared final cannot be extended (p. 420).

• All methods in a final class are implicitly final.

Get Java™ How To Program (Early Objects), Tenth Edition 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.