МОДУЛЬ 8 · УРОК 5
Polymorphism
Polymorphism means many forms. Same interface, different behavior.
30 minBeginnerJavaOOP
Polymorphism
Parent reference can hold child object. Method called based on runtime type.
Animal a = new Dog(); a.sound(); // Dog's version
Dynamic Binding
Java selects the method at runtime based on actual object type.
instanceof
if (a instanceof Dog d) { d.bark(); }
Interface Arrays
Shape[] shapes = { new Circle(5), new Rect(3,4) };
for (Shape s : shapes) s.area();
✅ Итоги урока
- Polymorphism: parent reference, child object.
- Dynamic binding: runtime method selection.
- instanceof checks actual type (use before downcasting).
- Interface arrays enable polymorphic iteration.
Next lesson: Object - root of all classes.
Test: Test: Polymorphism
3 вопроса