NhacVibe
Ảnh bìa Java : Inheritance, Interfaces and Polymorphism

Java : Inheritance, Interfaces and Polymorphism

Oddly Yogi · 6 lượt xem · 13 thg 11, 2026

Mô tả

A library lends books, DVDs and magazines, and each one has its own loan period. How do we write the lending code once and still let every kind behave differently? Like a wall socket that powers any appliance with the right plug, an interface lets code work with anything that follows its contract. In this video we extend a class with extends and super, override methods with @Override, see dynamic dispatch pick the right method at run time, stop overriding with final, write an abstract class, and design an interface with default and private methods. Then we close the hierarchy with sealed classes and interfaces, permits, final and non-sealed, and talk about composition versus inheritance. Shelf gains student members and an Item hierarchy of books, DVDs and magazines.

Versions: Java 25 LTS (Eclipse Temurin 25.0.5).

In this chapter:
00:00 One socket, many appliances
01:33 A student member: extends and super
03:24 Dynamic dispatch
05:24 Override safety: @Override and final
06:20 Abstract classes
09:14 Interfaces: the contract
11:07 Polymorphism: one loop, many kinds
12:04 Implementing two interfaces
13:24 Static methods in an interface
14:10 When two interfaces clash
15:26 Abstract class or interface?
16:16 Sealed classes and interfaces
18:14 Composition or inheritance?
19:21 Wrap up

This is Chapter 4 of 15 in the "Java" series.
#Java #Java25 #Programming #LearnJava #OOP