Answers for "python subclass"

1

python subclass

class SuperHero(object): #superclass, inherits from default object
    def getName(self):
        raise NotImplementedError #you want to override this on the child classes

class SuperMan(SuperHero): #subclass, inherits from SuperHero
    def getName(self):
        return "Clark Kent"

class SuperManII(SuperHero): #another subclass
    def getName(self):
       return "Clark Kent, Jr."

if __name__ == "__main__":
    sm = SuperMan()
    print sm.getName()
    sm2 = SuperManII()
    print sm2.getName()
Posted by: Guest on December-09-2020
0

python subcalss

class SubClass(SuperClass):
  super().__init__(self,atr1,atr2)
  super().SomeMethod(self)
  def OtherMethod(self,atr3):
    pass #Do Things
  def OverwrittenMethod(self,atr1,atr4):
    pass #If you create a method with the same name as on in the superclass
  		 #The one in the subclass will overwite the original methos
Posted by: Guest on September-16-2020

Python Answers by Framework

Browse Popular Code Answers by Language