<filename>docs/cornell CS class/lesson 22.Subclasses &Inheritance/demos/override.py
"""
A CS1110 lecture example for overriding of methods and class variables

This is just demonstrating syntax, so there are no specifications.

Authors: <NAME> (srm2), <NAME> (ljl2), and <NAME> (wmw2)
Date:    October 28, 2017 (Python 3 Version)
"""


class A(object):
    x = 3
    y = 5
    
    def f(self):
        self.g()
    
    def g(self):
        print('  this is A.g')

class B(A):
    y = 4
    z = 42
    
    def g(self):
        print('  this is B.g')
    
    def h(self):
        print('  this is B.h')

# Script code
if __name__ == '__main__':
    a = A()
    b = B()   
    
    print('a.f():')
    a.f()
    print('b.f():')
    b.f()
    print('b.y:', b.y)
    print('b.x:', b.x)
    print('A.y:', A.y)
    print('B.x:', B.x)

<filename>docs/cornell CS class/lesson 22.Subclasses &Inheritance/demos/override.py
"""
A CS1110 lecture example for overriding of methods and class variables

This is just demonstrating syntax, so there are no specifications.

Authors: <NAME> (srm2), <NAME> (ljl2), and <NAME> (wmw2)
Date:    October 28, 2017 (Python 3 Version)
"""


class A(object):
    x = 3
    y = 5
    
    def f(self):
        self.g()
    
    def g(self):
        print('  this is A.g')

class B(A):
    y = 4
    z = 42
    
    def g(self):
        print('  this is B.g')
    
    def h(self):
        print('  this is B.h')

# Script code
if __name__ == '__main__':
    a = A()
    b = B()   
    
    print('a.f():')
    a.f()
    print('b.f():')
    b.f()
    print('b.y:', b.y)
    print('b.x:', b.x)
    print('A.y:', A.y)
    print('B.x:', B.x)

A CS1110 lecture example for overriding of methods and class variables  This is just demonstrating syntax, so there are no specifications.  Authors: <NAME> (srm2), <NAME> (ljl2), and <NAME> (wmw2) Date:    October 28, 2017 (Python 3 Version) # Script code