Skip to main content
Module 4 · Lesson 1 of 29/22 in the course~15 min
Module lessons (1/2)

Interfaces and Contracts

Lesson preview5 hands-on exercises readyCourse Java · Module 4 — Interfaces and Dynamic Collections

Define clean interface, multiple implements A, B implementations, default methods, and composition vs inheritance.

What you'll learn in this lesson

  • Decouple what an object does from how it's made by defining interfaces as well.
  • Implement multiple contracts on the same class (implements A, B), bypassing the single inheritance limit.
  • Enrich existing contracts without breaking implementations thanks to default methods and static interface methods.

Overview

While inheritance (extends) binds two classes into a single hard kinship, one interface defines a ability contract ("can fly", "is serializable"). The same class can implement multiple interfaces at the same time.

The methods of an interface are implicitly public and abstract (up to Java 7) and do not require rewriting the public keyword in the interface itself — but must be declared public in the class that implements them!

Sections covered in this lesson

  1. 11. Definition and Basic Rules of a interface
  2. 22. Multiple Deployment (implements A, B)
  3. 33. Constants, default Methods and static Methods (Java 8+)
  4. 44. Interface or Abstract Class?
  5. 5Try it yourself
Pro Lesson · Module 4 — Interfaces and Dynamic Collections

Unlock "Interfaces and Contracts" and the full Course Java curriculum

Define clean `interface`, multiple `implements A, B` implementations, default methods, and composition vs inheritance.

Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.

  • Instant access to all advanced modules in Course Java plus 17 more courses
  • Hands-on browser exercises with automated test suites and solutions
  • 14-day money-back guarantee processed via Paddle.com

14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.