objectconversions
defgallonstoliters(){}
defmilestokilometers(){}
}
abstractclass
unitconversion
defgallonstoliters(){}
defmilestokilometers(){}
}object
inchestocentimeters
extends
unitconversion
}object
gallonstoliters
extends
unitconversion
}object
milestokilometers
extends
unitconversion
}
point中的getlocation方法返回的是point物件,如果想返回origin物件,需要origin類才行
objectorigin
extends
point
with
override
defgetlocation: point = super.getlocation
origin.move(2,3)
println(origin.tostring)
}
classpoint(x:int,y:int)
object
point
extends
defnew point(x,y)
} val
p = point(1,2)
println(p)
}
objectreverse
extends
args.reverse.foreach(arg => print(arg + " "))
}
objectcard
extends
enumeration
with
valm = value("♣")
valt = value("♠")
valh = value("♥")
valf = value("♦")
println(card.m)
println(card.t)
println(card.h)
println(card.f)
}
objectcard
extends
enumeration
with
valm = value("♣")
valt = value("♠")
valh = value("♥")
valf = value("♦")
defcolor(c:card.value)
color(card.h)
}
objectrgbextends
enumeration
with
valred = value(0xff0000,"red")
valblack = value(0x000000,"black")
valgreen = value(0x00ff00,"green")
valcyan = value(0x00ffff,"cyan")
valyellow = value(0xffff00,"yellow")
valwhite = value(0xffffff,"white")
valblue = value(0x0000ff,"blue")
valmagenta = value(0xff00ff,"magenta")
}
blog url:
《快學Scala》第六章習題解答
rt。package com.scalalearn.scala.main 快學scala 06習題 1.編寫乙個conversions物件,加入inchestocentimeters,gallonstoliters和milestokilometers方法 object conversions def...
第六章習題
r1.個無線網路執行在 基礎設施模式 下是什麼含義?如果某網路沒有執行在基礎設施模式下,那麼它執行在什麼模式下?這種執行模式與基礎設施模式之間有什麼不同?在基礎結構操作模式下,每個無線主機都通過基站連線到較大的網路。如果未在基礎架構模式下執行,則網路將在臨時模式下執行。在自組織模式下,無基站,節點僅...
第六章解答題
begin transaction declare errorsum int declare rid varchar 50 declare bid varchar 50 select rid rid from reader where rname 張無忌 select bid bid from bo...