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"
    }

  • 相关阅读:
    【Java】_2_Java程序入门第五课
    【算法和数据结构】_3_线性结构_栈
    Windows程序设计_17_鼠标_1
    网络基础知识1:集线器,网桥,交换机
    [hyddd安全性测试笔记2]浅淡静态代码分析工具
    [Ruby小记]初试~
    Arp攻击实战
    [hyddd安全性测试笔记1]URL Encode and URL Decode
    网络嗅探技术浅析
    Session小记
  • 原文地址:https://www.cnblogs.com/greencolor/p/2127993.html
Copyright © 2011-2022 走看看