Module lessons (1/2)
Interfaces and Contracts
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
defaultmethods andstaticinterface 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
- 11. Definition and Basic Rules of a
interface - 22. Multiple Deployment (
implements A, B) - 33. Constants,
defaultMethods andstaticMethods (Java 8+) - 44. Interface or Abstract Class?
- 5Try it yourself
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.