Written programs know the class, is the object-oriented meaning, the level of programming is broadly divided into several levels, basic syntax, functions, object-oriented, data structure, architecture, the higher the higher the level.
When creating a class, we usually wrap a function with a dependency as a class, and a class can be nested, called a parent class and a subclass, especially in Python, where all objects can be treated as a variable, and a nested example of a class is given below.
Class Metric (object):
def __init__ (self):
Self.var = "Hadoop"
def print_metric (self):
Print "I AM General metric:%s"% Self.var
Class Jmx_metric (Metric):
def __init__ (self):
Metric.__init__ (self)
def print_jmx_metric (self):
Print Metric.print_metric ()
Metric = Jmx_metric ()
Metric.print_jmx_metric ()
Executor Result:
I AM General Metric:hadoop
The parent class is written inside the subclass, inheriting the attribute and methods of the parent class, but the __init__ method of the parent class is executed before the variable is called.
This article from "Linux operation and Maintenance" blog, declined reprint!
Python Subclass Inherits Parent class