Inheritance in metaclasses
Inheritance, in a literal sense, means a child acquiring the properties of a parent and it means the same in the case of object-oriented programming too. A new class can inherit the attributes and methods of a parent class and it can also have its own properties and methods.
In this example, we will look at how inheritance works on metaclasses by creating two classes, California
and Pasadena
– California
being the parent class and Pasadena
the child class.
Let’s check these steps out to understand inheritance better:
- In the previous section, we already created two metaclasses that inherited type as their parent class –
IncomeStatementMetaClass
andBalanceSheetMetaClass
. We will start by creating the classCalifornia
with theIncomeStatement
metaclass:class California(metaclass = IncomeStatementMetaClass): profit = 4354365 loss...