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