object test15 {
//类的继承
abstract class Person(name: String,age: Int){
println("constructing Person")
def walk(): Unit ={
println(name +" person walk")
}
}
class Student(name:String,age:Int,studentNo:String) extends Person(name,age){
println("constructing Student")
//方法重写
override def walk(): Unit = {
println(name+" student walk")
}
}
def main(args: Array[String]): Unit = {
val student=new Student("jack",25,"no.128")
student.walk()
//匿名类
//当某个类在程序中只使用一次时,可以将类定义为匿名类
val s=new Person("Paul",15){
override def walk(): Unit = {
println("匿名walk")
}
}
s.walk()
}
}