How to use simple class inheritance in Python

1 Answer

0 votes
class Pets:
    name = "class Pets"

    @classmethod
    def method(cls):
        print("Class Pets: {}".format(cls.name))


class Cats(Pets):
    name = "class Cats"


class Dogs(Pets):
    name = "class Dogs"


p = Pets()
p.method()

c = Cats()
c.method()

d = Dogs()
d.method()


'''
run:
 
Class Pets: class Pets
Class Pets: class Cats
Class Pets: class Dogs

'''

 



answered Feb 10, 2018 by avibootz
edited Feb 10, 2018 by avibootz

Related questions

1 answer 178 views
1 answer 145 views
1 answer 223 views
223 views asked Jul 4, 2017 by avibootz
1 answer 203 views
...