Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Inheritance
#3
When you define a method in a subclass which has the same name as the superclass, you replace that method in the subclass. So in this case you'd lose the print("Animal created") behavior by overriding the __init__ method. Explicitly calling the superclass __init__ method by that name retains the behavior, so that you have both behaviors. Normally, we use super() for that instead; this is useful in examples where the superclass changes, or there are other more complex situations.. What tutorial are you using, and what Python version?
Reply


Messages In This Thread
Inheritance - by Athul - Aug-09-2018, 08:03 AM
RE: Inheritance - by ichabod801 - Aug-09-2018, 12:54 PM
RE: Inheritance - by micseydel - Aug-09-2018, 06:24 PM
RE: Inheritance - by Athul - Aug-11-2018, 07:35 AM
RE: Inheritance - by yksingh1097 - Aug-11-2018, 09:37 AM
RE: Inheritance - by snippsat - Aug-11-2018, 10:23 AM
RE: Inheritance - by ichabod801 - Aug-11-2018, 12:47 PM
RE: Inheritance - by yksingh1097 - Aug-11-2018, 06:48 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020