Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A problem with child class
#2
You can add the speed at the __init__() or maybe just use it in the run().

def __init__(self, name, age):
        self.name = name
        self.age = age
        self.speed = 'Normal'
Then..

class Bulldog(Dog):
    def run(self, speed):
        self.speed = speed
        return f'{self.name} runs {self.speed}'
Or

class RussellTerrier(Dog):
    def run(self, speed):
        return f'{self.name} runs {speed}'
Reply


Messages In This Thread
A problem with child class - by Truman - Jul-01-2018, 11:22 PM
RE: A problem with child class - by gontajones - Jul-02-2018, 12:35 AM
RE: A problem with child class - by ichabod801 - Jul-02-2018, 12:37 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  class definition and problem with a method HerrAyas 2 298 Apr-01-2024, 03:34 PM
Last Post: HerrAyas
Question __init__ of Child Class zero_fX0 4 1,792 Mar-22-2023, 05:23 PM
Last Post: deanhystad
  Using one child class method in another child class garynewport 5 1,669 Jan-11-2023, 06:07 PM
Last Post: garynewport
  Child class inheritance issue eakanathan 3 1,377 Apr-21-2022, 12:03 PM
Last Post: deanhystad
  Can we access instance variable of parent class in child class using inheritance akdube 3 14,036 Nov-13-2020, 03:43 AM
Last Post: SalsaBeanDip
  Practice problem using lambda inside the class jagasrik 3 2,204 Sep-12-2020, 03:18 PM
Last Post: deanhystad
  calling on a method from one class into another class which is not a child NABA 5 2,877 Apr-29-2020, 07:49 PM
Last Post: deanhystad
  [split] Python Class Problem astral_travel 12 5,053 Apr-29-2020, 07:13 PM
Last Post: michael1789
  Python Class Problem JPCrosby 2 2,314 Apr-28-2020, 06:18 PM
Last Post: buran
  Class problem duckduck23 2 2,044 Feb-10-2020, 08:52 PM
Last Post: jefsummers

Forum Jump:

User Panel Messages

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