package com.spark.scala.basics
/**
* 1.
*/
class Person {
val count = 3
val countArray = new Array[Int](count)
}
class Sporter extends Person {
override val count: Int = 5
}
object OverridField {
def main(args:Array[String]): Unit ={
val s = new Sporter
println(s.countArray.length) // 0,提前定义
}
}
package com.spark.scala.basics
/**
* 1.
*/
class Person {
val count = 3
val countArray = new Array[Int](count)
}
class Sporter extends {
override val count: Int = 5
} with Person
object OverridField {
def main(args:Array[String]): Unit ={
val s = new Sporter
println(s.countArray.length) // 5
}
}
classProgramer(val name: String, val salary: Double) {
final override def equals(other: scala.Any): Boolean = {
val that = other.asInstanceOf[Programer]
if (that == null) false
else name == that.name && salary == that.salary
}
final override def hashCode(): Int = {
name.hashCode * 17 + salary.hashCode() * 9
}
}