inheritance
yag
yagnesh at live.com
Thu Apr 5 12:50:50 EDT 2012
Hello,
I am new to python (or to any programming language). My first post on this list,
so please go easy. Apologies if its a FAQ.
Here is what I have
--------------------------------
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
class A(object):
def __init__(self, a):
print('a = ', a)
self.a = a
def foo(self):
print('printing from foo in A = ',self.a)
class B(A):
def __init__(self, b, a):
super(B, self).__init__(a)
print('b = ', b)
self.b = b
def foo(self):
print('printing from foo in B = ',self.b)
class C(B):
def __init__(self, c, b, a):
super(C, self).__init__(b, a)
print('c = ', c)
self.c = c
def foo(self):
print('printing from foo in C = ',self.c)
x = C(3,2,1)
x.foo()
--------------------------------
three classes A,B,C and instance x.
now how can I call methods foo in class A and B using 'x' instance. (I hope I
could pronounce the terminology correct)
Thanks.
--
YYR
More information about the Python-list
mailing list