Course contentsShow
← Java
Lesson 520 of 2,87012. Abstract Classes and InterfacesFree lesson

Private Methods in Interfaces: Java 9 Introduction

Discover how Java 9 added private methods to interfaces to reduce code duplication between default methods.

Private Methods in Interfaces: Java 9 Introduction

What you'll learn: How Java 9 introduced private methods to interfaces to eliminate code duplication between default methods.


The Problem Before Java 9

Once Java 8 added default methods to interfaces, developers could provide concrete implementations directly in interfaces. However, when multiple default methods shared common logic, there was no good way to extract that logic into a helper method. You'd either duplicate code or violate interface design principles by exposing internal helper methods as public.

What Are Private Methods in Interfaces?

Starting in Java 9, interfaces can declare private methods to support code reuse between default (and static) methods. These private methods are completely hidden from implementing classes—they're internal implementation details of the interface itself.

Think of it like organizing a company's internal processes: default methods are the public services you offer customers, while private methods are the internal procedures your team uses behind the scenes.

Two Flavors

  1. Private instance methods — Called by default methods, can use this
  2. Private static methods — Called by static or default methods, cannot use this

Both exist solely to reduce duplication within the interface.

Why This Matters

Before private methods, you'd repeat logic across default methods or make helper methods public (polluting the interface contract). Now you can write clean, DRY (Don't Repeat Yourself) code while keeping your interface's public API minimal and focused.

Private methods cannot be overridden or accessed by implementing classes—they're completely encapsulated within the interface.

Key Takeaway: Java 9's private interface methods let you refactor common logic out of default methods without exposing helper methods publicly, keeping interfaces clean and maintainable.