8.4.2 方法的重写
scala 明确规定,重写一个非抽象方法需要用override
修饰符,明确需要调用超类的方法使用super
关键字
package com.atguigu
object Student {
def main(args: Array[String]): Unit = {
val s = new Student
s.say()
}
}
class Student extends Person {
def study(): Unit = {
println(this.name + " good good study, day day up")
super.say()
}
override def say(): Unit = {
super.say()
println("子类的say")
}
}
class Person {
var age = 10
var name = "小明"
def say(): Unit = {
println("Person的say方法:" + this.age)
}
}