scala特质练习

object 练习 {

  abstract class Coder {
    var name: String = _
    var age: Int = _

    def eat(): Unit

    // 技能
    def skill(): Unit

  }

  class JavaCoder extends Coder {
    override def eat(): Unit = println("Java程序员吃大白菜,和大米粥")

    override def skill(): Unit = println("精通Java")
  }

  class PythonCode extends Coder {
    override def eat(): Unit = println("Python程序员吃小白菜,喝小米粥")

    override def skill(): Unit = println("精通Python")
  }

  trait BigData {
    def learningBigData(): Unit = {
      println("来到黑马之后")
      println("掌握了:Hadoop、Zookeeper、HBase、Hive、Spark、Flink等")
      println("项目经验:企业级360°全方位用户画像、千亿级数仓、黑马推荐系统、电信信号强度诊断")
    }
  }

  class PartJavaCode extends JavaCoder with BigData {
    override def eat(): Unit = {
      super.eat()
      println("精通Java + BigData的程序员,吃牛肉,和牛肉汤")
    }

    override def skill(): Unit = {
      super.skill()
      learningBigData()
    }
  }

  class PartPythonCoder extends PythonCode with BigData {
    override def eat(): Unit = {
      super.eat()
      println("精通Python + BigData的程序员,吃羊肉,喝羊肉汤")
    }

    override def skill(): Unit = {
      super.skill()
      learningBigData()
    }
  }

  def main(args: Array[String]): Unit = {
    println("普通Java程序员")
    val jc = new JavaCoder
    jc.name = "小歪歪"
    jc.age = 20
    println(jc.name, jc.age)
    jc.eat()
    jc.skill()

    println("-" * 20)

    println("精通Java + BigData的程序员")
    val pjc = new PartJavaCode
    pjc.name = "黑马一哥"
    pjc.age = 30
    println(pjc.name, pjc.age)
    pjc.eat()
    pjc.skill()
  }

}
上一篇:Hutool工具获取系统资源使用情况


下一篇:数据类型课堂笔记