返回顶部

收藏

python虚函数定义

更多
class SpecialCase:
    def amethod(self): 
       print 'special'

class NormalCase:
    def amethod(self): 
       print 'normal'

def appropriateCase(isnormal=1):
    if isnormal: 
       return NormalCase()
    else: 
       return SpecialCase()

aninstance = appropriateCase(isnormal=0)
aninstance.amethod()

标签:Python,Class

收藏

0人收藏

支持

0

反对

0

»更多 您可能感兴趣的代码
  1. 2015-04-04 09:41:16python面向对象:__del__函数使用 by jack.chen
  2. 2015-04-13 09:39:34重写内置的__str__方法 by wubai
  3. 2015-04-27 09:21:44python类的成员变量定义 by 西国の海妖
  4. 2015-05-05 14:53:44python自定义list by 阮小七
  5. 2015-05-09 17:34:43Python定义类 by Solon.Ring
  6. 2015-03-16 11:47:13python抽象类定义 by 阿明娃儿
  7. 2015-04-04 18:40:38python Class: __getitem__ 示例 by 西国の海妖
  8. 2015-04-13 14:33:07Add a member variable to a class on the fly by 西国の海妖
  9. 2015-04-27 10:12:18生成类属性 by 阮小七
  10. 2015-03-17 09:25:05Add a class member variable on the fly by 风云轩
  11. 2015-03-17 09:34:41Python多继承 by wubai

发表评论