[Tutor] Inheritance in classes
alan.gauld at btinternet.com
Tue Apr 8 10:27:59 CEST 2014
On 08/04/14 06:44, Santosh Kumar wrote:
> Can i mask the parent attibutes in the child. let me give a quick example.
> In : class a:
> ...: value1 = 1
> ...: value2 = 2
> In : class b(a):
> ...: value3 = 3
Note that these are class variables and not instance
> In : obj1 = b()
> In : obj1.value1
> Out: 1
> In : obj1.value3
> Out: 3
> If you notice in the below example you will see that the child class
> object ``obj1`` has inherited all the attibutes of the parent class.
Yes that's what inheritance means.
> there a way by which i can make the child class not inherit some of the
> properites of parent class.
But you can change the inherited values by masking them with your local
versions, which could be None.
value1 = None
obj2 = c()
print(obj2.value1) -> None
Author of the Learn to Program web site
More information about the Tutor