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

原文地址:https://www.cnblogs.com/greencolor/p/2127993.html