Chinaunix首页 | 论坛 | 博客
  • 博客访问: 62317
  • 博文数量: 33
  • 博客积分: 841
  • 博客等级: 准尉
  • 技术积分: 340
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-20 20:54
文章分类

全部博文(33)

文章存档

2011年(33)

分类: Python/Ruby

2011-02-21 08:02:42

  1. #父类的定义
  2. class Base
  3.         def meth
  4.             puts "This is Base#meth"
  5.         end
  6. end

  7. #继承类Derived的定义
  8. class Derived < Base
  9.         def meth
  10.             puts "This is Derived#meth"
  11.         end
  12.         
  13.         #Derived的实例方法obj2.meth没有定义
  14.         undef_method(:meth)
  15. end

  16. #类Test1继承Derived
  17. class Test < Derived
  18.         def meth
  19.             puts "This is Test1#meth"
  20.         end
  21.     
  22.      #
  23.         undef_method(:meth)
  24. end

  25. #Test的实例方法obj1.meth没有定义
  26. obj1 = Test.new
  27. obj2 = Derived.new
  28. obj1.meth
  29. obj2.meth
阅读(1460) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~