Inheritance...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • KraftDiner

    #1

    Inheritance...

    I have a base class

    class geometry(object ):
    def __init__(self):
    self.blue = 1
    self.red = 2
    def render(self):
    pass

    class square(geometry ):
    def __init__(self):
    super(square, self).__init__( )
    def render(self)
    print 'square'

    class circle(geometry ):
    def __init__(self):
    super(square, self).__init__( )
    def render(self)
    print 'square'

    objLst = []
    objLst.append(s quare())
    objLst.append(c ircle())

    for obj in objLst:
    obj.render()
    print obj.blue

    What is wrong with this... I will not print blue... (1)

  • Duncan Booth

    #2
    Re: Inheritance...

    KraftDiner wrote:
    [color=blue]
    > I have a base class
    >
    > class geometry(object ):
    > def __init__(self):
    > self.blue = 1
    > self.red = 2
    > def render(self):
    > pass
    >
    > class square(geometry ):
    > def __init__(self):
    > super(square, self).__init__( )
    > def render(self)
    > print 'square'
    >
    > class circle(geometry ):
    > def __init__(self):
    > super(square, self).__init__( )
    > def render(self)
    > print 'square'
    >
    > objLst = []
    > objLst.append(s quare())
    > objLst.append(c ircle())
    >
    > for obj in objLst:
    > obj.render()
    > print obj.blue
    >
    > What is wrong with this... I will not print blue... (1)
    >
    >[/color]
    a) No need to post your question twice.

    b) When posting your code, you should post the actual code you have a
    problem with. The code you posted here contains syntax errors, so I presume
    you miscopied, or paraphrased it.

    So, first fix your syntax errors.
    Then correct the occurrences of the word 'square' in the class 'circle'.
    Then your code will print 1.

    Comment

    Working...