Answers for "how to inherit a class in python"

0

how to inherit a class in python

class awwab(object):
    def __init__(self, name, age):
        self.name = name
        self.age = age
    
    def speak(self):
        print("Hello, my name is",self.name,"and I am",self.age,"years old!")
        
awwabasad = awwab("Awwab Asad", 11)
print(awwabasad.speak())

class naail(awwab):
    def __init(self, name, age):
        super().__init__(self, name, age)
    
naailasad = naail("Naail Asad", 8)
print(naailasad.speak())
Posted by: Guest on July-31-2021
0

how to inherit a class in python

class Bird():
        def eat(self):
                print ("eating")
 
class Sparrow(Bird):
        def sound(self):
                print ("ChiChi!")
 
birdobj = Sparrow()
birdobj.eat()
birdobj.sound()
Posted by: Guest on July-10-2020

Code answers related to "how to inherit a class in python"

Python Answers by Framework

Browse Popular Code Answers by Language