Course contentsShow
← Java
Lesson 430 of 2,87010. Inheritance FundamentalsFree lesson

Combining final with Other Modifiers

Understand how final interacts with abstract, static, and access modifiers on methods and classes.

Combining final with Other Modifiers

You'll learn: How the final keyword works alongside other modifiers like abstract, static, and access modifiers on methods and classes.

Understanding Modifier Compatibility

The final keyword doesn't exist in isolation—it appears alongside other modifiers you've already learned. Some combinations are perfectly valid, while others create logical contradictions that Java won't allow.

final with Access Modifiers

You can freely combine final with any access modifier (public, protected, private, or package-private). These control who can see a member, while final controls whether it can be changed or overridden.

Valid combinations:

  • public final class String (the class you know!)
  • private final void helper() (can't be overridden, only this class sees it)
  • protected final int getSize() (visible to subclasses but not overridable)

final with static

Methods can be both static and final. Since static methods aren't inherited in the same way as instance methods (they belong to the class, not objects), the final here just reinforces that subclasses can't hide the method with their own version. It's valid but somewhat redundant.

final with abstract: ILLEGAL

This is a logical impossibility. The abstract modifier means "subclasses must override this," while final means "subclasses cannot override this." Java will reject abstract final combinations with a compile error—they contradict each other completely.

Think of it like a door labeled "Must Enter" and "Cannot Enter" simultaneously—it makes no sense!

Typical Patterns

Most commonly you'll see: public final class, public static final (constants), and occasionally private final methods for internal helpers you want locked down.

Key Takeaway: final combines freely with access and static modifiers, but never with abstract—their purposes are mutually exclusive.