SCALA中的抽象类代码样例

时间:2021-11-17 00:08:34
package com.hengheng.scala

class AbstractClass {

}
abstract class People {
  def speak

  val name : String
  var age : Int
}
class Worker extends People {
  def speak {
    println("Hello, Worker!!!")
  }
  val name = "Rocky"
  var age = 27
}
object AbstractClass extends App {
  val worker = new Worker
  worker.speak
  println(worker.name + ":" + worker.age)
}

  输出:

Hello, Worker!!!
Rocky:27