zoukankan      html  css  js  c++  java
  • double inherit

    class person {
    public variable name
    public variable age
    constructor {{inname "A N Other"} {inage 21}} {
    set name $inname
    set age $inage
    }
    }

    person .kk
    # Second base class

    class cost {
    public variable startup
    public variable annual
    constructor {
      {yearly 12000}
      {newstart 0}
         } {
      set startup $newstart  
         } {
      set annual $yearly
         }
    method getmonthly {} {
    return [expr $annual/12.]
    }
    }

    cost .kb

    # class that multiple inherits


    class costa {
    public variable startup
    public variable annual
    constructor { args } {
         }
    method getmonthly {} {
    return [expr $annual/12.]
    }
    }

    costa .kt
    .kt configure -startup 22000 -annual 234323
    .kt getmonthly


    class costb {

    public variable startup
    public variable annual
    constructor { } {
     set kkt 22
         } {
            set ktt 23
     }
    method getmonthly {} {
    return [expr $annual/12.]
    }
    }

    costb .ktc
    .ktc configure -startup 22000 -annual 234323
    .ktc getmonthly


    class employee {
    inherit person cost
    variable empnumber
    constructor {empn} {
    # Construct a cost ...
    #cost::constructor ?yearly? ?newstart?

    #cannot use cost::constructor -yearly 150002 -newstart 233
    cost::constructor   150003  233} {
    # automatically constructs a person
    # with all parameters defaulted. Then the extra
    # variables are set up here
    set empnumber $empn
    }
    }

    employee .kc 300
    # Test application to use employee class

    # Constructor test

    employee boris 77653
    employee brenda 72727

    # change various inherited settings!

    boris configure -name "Boris Morris"
    brenda configure -age 50
    brenda configure -annual 18500

    # Retreive and print various attributes

    foreach teammember {boris brenda} {
    set name [$teammember cget -name]
    set paythem [$teammember getmonthly]
    puts "Pay $name at $paythem per month"
    }

  • 相关阅读:
    css命名书写规范小结。
    不断学习,充实自己。
    【openGL】画正弦函数图像
    【openGL】画五角星
    【openGL】画圆
    【openGL】画直线
    【网络资料】Astar算法详解
    【Agorithm】一次一密加密解密算法
    【HTML5】 web上的音频
    【sicily】卡片游戏
  • 原文地址:https://www.cnblogs.com/greencolor/p/2127993.html
Copyright © 2011-2022 走看看