Example of class inheritance and method overriding in Python


/ Published in: Python
Save to your folder(s)

This simple example will show you how to inherit a class from a parent class. I have to apologise for some grammar mistakes that I've probably put in the comments, but English is not my native language.

If you execute this code, the output will be:


Here comes Lois Lane

Here comes Jimmy Olsen

Here comes Clark Kent

...but his secret identity is 'Superman' and he's a super-hero!


--> Let's see what a man can do:


Jimmy Olsen walks

Lois Lane says: 'Oh no, we're in danger!'

--> Let's see what a superman can do:


Clark Kent walks

Clark Kent says: 'This is a job for SUPERMAN!'

Superman run at the speed of light

Superman fly up in the sky

Superman uses his x-ray vision

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.