Class Thing
Class Animal
Class Other -superclass {Animal Thing} Thing instproc init {args} {
puts "here is init from:thing"
eval $self next $args
}
Thing instproc move {} {
puts "here is move from:thing"
} Animal instproc init {args} {
puts "here is init from:animal"
eval $self next $args
}
Animal instproc move {} {
puts "here is move from:animal"
eval $self next
} Other instproc init {args} {
puts "here is init from:other"
eval $self next $args
}
Other instproc move {} {
puts "here is move from:other"
eval $self next
}
Other other
other move

输出:

here is init from:other
here is init from:animal
here is init from:thing
here is move from:other
here is move from:animal
here is move from:thing

上面是简单地继承两个父类,在调用next的时候,顺序是按继承时候的从左到右的顺序,依次调用。

如果是这样:

Class theOne
Class Thing -superclass theOne
Class Animal
Class Other -superclass {Thing Animal} theOne instproc init {args} {
puts "here is init from:theOne"
eval $self next $args
}
theOne instproc move {} {
puts "here is move from:theOne"
eval $self next
} Thing instproc init {args} {
puts "here is init from:thing"
eval $self next $args
}
Thing instproc move {} {
puts "here is move from:thing"
eval $self next
} Animal instproc init {args} {
puts "here is init from:animal"
eval $self next $args
}
Animal instproc move {} {
puts "here is move from:animal"
eval $self next
} Other instproc init {args} {
puts "here is init from:other"
eval $self next $args
}
Other instproc move {} {
puts "here is move from:other"
eval $self next
}
Other other
other move

输出:

here is init from:other
here is init from:thing
here is init from:theOne
here is init from:animal
here is move from:other
here is move from:thing
here is move from:theOne
here is move from:animal

OTCL的多继承的更多相关文章

  1. OTCL,面向对象的脚本一

    Otcl 简介 面向对象的脚本语言 类变量和类方法 Otcl的基类称为Object(类的名字,不是面向对象中的"对象"),所以的Otcl类都是从Object派送来的. 直接贴代码, ...

  2. javaScript的原型继承与多态性

    1.prototype 我们可以简单的把prototype看做是一个模版,新创建的自定义对象都是这个模版(prototype)的一个拷贝 (实际上不是拷贝而是链接,只不过这种链接是不可见,给人们的感觉 ...

  3. JavaScript的继承实现方式

    1.使用call或apply方法,将父对象的构造函数绑定在子对象上 function A(){ this.name = 'json'; } function B(){ A.call(this); } ...

  4. javascript中的继承与深度拷贝

    前言 本篇适合前端新人,下面开始...... 对于前端新手来说(比如博主),每当对js的对象做操作时,都是一种痛苦,原因就是在于对象的赋值是引用的传递,并非值的传递,虽然看上去后者赋值给了前者,他们就 ...

  5. 谈谈一些有趣的CSS题目(四)-- 从倒影说起,谈谈 CSS 继承 inherit

    开本系列,讨论一些有趣的 CSS 题目,抛开实用性而言,一些题目为了拓宽一下解决问题的思路,此外,涉及一些容易忽视的 CSS 细节. 解题不考虑兼容性,题目天马行空,想到什么说什么,如果解题中有你感觉 ...

  6. JS继承类相关试题

    题目一: //有关于原型继承的代码如下:function Person(name) {   this.name = name;}Person.prototype = {     getName : f ...

  7. JS继承之寄生类继承

    原型式继承 其原理就是借助原型,可以基于已有的对象创建新对象.节省了创建自定义类型这一步(虽然觉得这样没什么意义). 模型 function object(o){ function W(){ } W. ...

  8. JS继承之借用构造函数继承和组合继承

    根据少一点套路,多一点真诚这个原则,继续学习. 借用构造函数继承 在解决原型中包含引用类型值所带来问题的过程中,开发人员开始使用一种叫做借用构造函数(constructor stealing)的技术( ...

  9. JS继承之原型继承

     许多OO语言都支持两种继承方式:接口继承和实现继承.接口继承只继承方法签名,而实现继承则继承实际的方法.如前所述,由于函数没有签名,在ECMAScript中无法实现接口继承.ECMAScript只支 ...

随机推荐

  1. HttpWebResponse类

    HttpWebResponse类的作用用于在客户端获取返回的响应的信息,还记得HttpResponse类吗?你是否在写B/S程序的时候,经常用到Response.Write()呢? HttpRespo ...

  2. java数组复制的方式和效率比较

    java中,数组的复制有以下三种方式: 1. 调用System.arraycopy(Arrays.copyOfRange可以当作第四种,但是底层调用的是System.arraycopy,所以,认为是同 ...

  3. Spring MVC对象转换说明

    在Spring MVC之前我们需要在Servlet里处理HttpServletRequest参数对象,但这个对象里的属性都是通用类型的对象(如字符串),处理起来很繁琐并且容易出错,而Spring MV ...

  4. iOS 10 (X8)上CoreData的使用(包含创建工程时未添加CoreData)

    1.在创建工程时未添加CoreData,后期想要使用CoreData则要在工程Appdelegate.h文件中添加CoreData库和CoreData中的通道类(用来管理类实例和CoreData之间的 ...

  5. IOS MVC

    简单的理解: V对M是不能通讯的. C对M通讯:API M对C通讯:Notification,KVO C对V通讯:Outlet V对C通讯:Target-action, Delegate,Dataso ...

  6. [置顶] Hibernate从入门到精通(五)一对一单向关联映射

    上次的博文中Hibernate从入门到精通(四)基本映射我们已经讲解了一下基本映射和相关概念,接下来我们会讲稍微复杂点的映射——关系映射. 关系映射分类 关系映射即在基本映射的基础上处理多个相关对象和 ...

  7. 【Android开发经验】LayoutInflater—— 你可能对它并不了解甚至错误使用

    今天,看到了一篇文章讲LayoutInflater的使用方法.瞬间感觉自己对这个类确实不够了解,于是简单的看了下LayoutInflater类的源码.对这个类有了新的认识. 首先.LayoutInfl ...

  8. 执行此安装程序之前,必须安装 32 位 Windows 映像处理组件(WIC)解决的方法

    我们在Windows Service 2003上安装 Microsoft .NET Framework4.0时常常出现以下的报错 执行此安装程序之前,必须安装 32 位 Windows 映像处理组件( ...

  9. 从一段代码看fork()函数及其引发的竞争

    首先来看一段从<UNIX环境高级编程>中摘录的一段很有意思的代码.借此我们再来谈谈fork()函数的一些问题. #include "apue.h" static voi ...

  10. Jackson的Json转换

    public class JacksonJsonUtil { private static ObjectMapper mapper; /** * 获取ObjectMapper实例 * @param c ...