package com.sparktest
/**
*继承:
* 1.成员没有被赋值,则必须是抽象的
* 2.若想获取父类的数值,则需要提前定义
*
*/
abstract class Person {
val conter:Int
val conterArray = new Array[Int](conter)
}
class Sporter extends Person{
override val conter: Int = 5
}
//提前定义
//class Sporter extends {
// override val conter: Int = 5
//} with Person
object OverrideField extends App {
val s = new Sporter
println(s.conterArray.length)//0
}
package com.sparktest
/**
*继承:
* 1.成员没有被赋值,则必须是抽象的
* 2.若想获取父类的数值,则需要提前定义
*
*/
class Person {
val conter:Int = 3
val conterArray = new Array[Int](conter)
}
//class Sporter extends Person{
// override val conter: Int = 5
//}
//提前定义
class Sporter extends Person {
override val conter: Int = 5
}
object OverrideField extends App {
val s = new Sporter
println(s.conterArray.length)//0
}
package com.sparktest
/**
*继承:
* 1.成员没有被赋值,则必须是抽象的
* 2.若想获取父类的数值,则需要提前定义
*
*/
class Person {
val conter:Int = 3
val conterArray = new Array[Int](conter)
}
//class Sporter extends Person{
// override val conter: Int = 5
//}
//提前定义
class Sporter extends {
override val conter: Int = 5
} with Person
object OverrideField extends App {
val s = new Sporter
println(s.conterArray.length)//5
}
package com.sparktest
/**
*继承:
* 1.成员没有被赋值,则必须是抽象的
* 2.若想获取父类的数值,则需要提前定义
*
*/
abstract class Person {
val conter:Int
val conterArray = new Array[Int](conter)
}
class Sporter extends Person{
override val conter: Int = 5
}
class Programmer(val name:String, val salary:Double){
final override def equals(other:Any): Unit ={
// 两个对象真正相等的具体的比较逻辑
val that = other.asInstanceOf[Programmer]
if(that == null) false
else name == that.name && salary == that.salary
}
final override def hashCode(): Int = name.hashCode() * 17 + salary.hashCode() * 9
}
//提前定义
//class Sporter extends {
// override val conter: Int = 5
//} with Person
object OverrideField extends App {
val s = new Sporter
println(s.conterArray.length)//0
}