通過python的abc模塊能夠實現虛函數;
首先在開頭from abc import ABCMeta, abstractmethod
例子 :
#!/usr/bin/python
#coding=utf-8
from abc import ABCMeta, abstractmethod
class Base():
__metaclass__=ABCMeta #必須先聲明
def __init__(self):
pass
@abstractmethod #虛函數
def get(self):
print 'base get'
pass
class Derivel(Base):
def get(self):
print "Derivel get"
class Derivel2(Base):
def get(self):
print "Derivel2 get"
A = Derivel()
B = Derivel2()
A.get()
B.get()
