Python Forum
inheritence vs instanciation? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: inheritence vs instanciation? (/thread-2087.html)



inheritence vs instanciation? - hsunteik - Feb-18-2017

what is the different between inheritence and instanciation?
They both have same function and uses.
so how are the two used differently?


RE: inheritence vs instanciation? - Ofnuts - Feb-18-2017

(Feb-18-2017, 04:31 AM)hsunteik Wrote: what is the different between inheritence and instanciation?
They both have same function and uses.
so how are the two used differently?

Totally different things.

"inheritance" is defining a new class by modifying/specializing the "base" class. For instance you have a  class Mammal, from which you derive a class Dog, from which you derive a class Labrador. So Labrador inherits from Dog which inherits from Mammal.

"instanciation" is creating objects ("instances") of the class. Instances of Labrador are called "Fido", "Snoopy", etc... Note that Fido, is a Labrador, but is also a Dog and a Mammal, so methods defined for Mammal are also available for Dog and Labrador (but of course these class can override said methods to provide their own).