從大數據菜鳥走上大師的歷程 Scala 第十二講 trait

trait 相似於Java 中的Interface 但有差異 trait能夠繼承trait而且在trait 能夠寫抽象的方法,也能夠具體實現方法 實例以下
trait Walk
{
 html

def walk(){}
}
class person extends Walk
{
  println("hello -----")
  override def walk(){println("Let's have a walk ")}
}
trait Run extends Walk
{
  def run()
  {
    println("go for a walk and run around ")
  }
}
object HelloTrait {
  def main(args: Array[String]): Unit = {
    val tt = new person with Run
    tt.run()  
  }
}
打印結果 :
hello -----
go for a walk and run around

如今正是學習大數據的最好機遇,不花一分錢就能夠成爲大數據高手,實現年薪50萬的夢想。微信

王家林的第一個中國夢:免費爲全社會培養100萬名優秀的大數據從業人員!ide

若是您有興趣請點擊這個連接進入大數據的學習學習

http://blog.sina.com.cn/s/blog_8fbd39ee0102vto3.html大數據

若是您確實感受視頻教程有幫助,您能夠經過王家林老師的微信號18610086859發紅包捐助大數據、互聯網+、O2O、工業4.0、微營銷、移動互聯網等系列免費實戰課程url

您也能夠經過如下二維碼關注 DT大數據夢工廠視頻

從大數據菜鳥走上大師的歷程 <wbr><wbr>Scala <wbr><wbr>第十一講 <wbr><wbr>extends
相關文章
相關標籤/搜索