考虑下面的代码:
class parent_print():
def print_word(self):
self.print_hello()
class child_print(parent_print):
def print_hello(self):
print('Hello')
basic_print = child_print()
basic_print.print_word()
这里我假设
打印你好
是父类中的虚拟函数。父对象(parent_print)的所有子对象都将实现一个名为
打印你好
.这样所有的孩子都可以调用一个函数
打印单词
并根据子对象的方法实现对print_hello函数进行适当的绑定。
但是在C++语言中,我们需要特别指出,函数在父类中是虚拟的。
事实上的
关键字,并使用函数析构函数符号~。
但是,在python中,如果不在python父类中提到函数,这怎么可能呢
打印你好
是一个虚拟的功能。
我假设python使用的概念是虚拟函数,如果我错了,请纠正我并解释这个概念。