Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Polymorphism | Polymorphism
Object-Oriented Programming in Python
course content

Contenu du cours

Object-Oriented Programming in Python

Object-Oriented Programming in Python

1. Classes and Objects
2. Encapsulation
3. Inheritance
4. Polymorphism

book
Polymorphism

Polymorphism is a class property to modify superclass functionality. Methods or attributes can have various meanings and purposes inside the different classes. Methods in the superclass are virtual, that means they can be overridden in the children's classes.

Code

Each class has the say method. But each method performs different things.

123456789101112131415161718
class Bird: def say(self): print('Chirp') class Duck(Bird): def say(self): print('Quack') class Rooster(Bird): def say(self): print('Cock-a-doodle-do') bird = Bird() bird.say() duck = Duck() duck.say() rooster = Rooster() rooster.say()
copy

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 4. Chapitre 1

Demandez à l'IA

expand
ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

course content

Contenu du cours

Object-Oriented Programming in Python

Object-Oriented Programming in Python

1. Classes and Objects
2. Encapsulation
3. Inheritance
4. Polymorphism

book
Polymorphism

Polymorphism is a class property to modify superclass functionality. Methods or attributes can have various meanings and purposes inside the different classes. Methods in the superclass are virtual, that means they can be overridden in the children's classes.

Code

Each class has the say method. But each method performs different things.

123456789101112131415161718
class Bird: def say(self): print('Chirp') class Duck(Bird): def say(self): print('Quack') class Rooster(Bird): def say(self): print('Cock-a-doodle-do') bird = Bird() bird.say() duck = Duck() duck.say() rooster = Rooster() rooster.say()
copy

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 4. Chapitre 1
Nous sommes désolés de vous informer que quelque chose s'est mal passé. Qu'est-il arrivé ?
some-alt