目录:
*1:Scala面向对象
*2:构造器:
*3:继承:
*4:伴生
1、Scala面向对象:
类里面定义的val,new新对象的时候也是不能更改的,用占位符的时候,需要在前面加上具体的数据类型,否则推导不出来:
private[this]后类里面的属性是私有化的,在类外面不能被调用:
object SimepleObjectApp {
def main(args: Array[String]): Unit
=
{
val peopel=new Peopel
peopel.name="等你来"
println(peopel.name+":"+peopel.age+":")
println(peopel.code())
peopel.pickgirl
peopel.printInfo()
}
class Peopel{
//类里面定义属性
var name:String =_
val age =10
private[this] val gender="male"
def printInfo(): Unit ={
println("gender:"+gender)
}
def code()={
name+"coding..."
}
def pickgirl: Unit ={
println(name+"pinckgirling...")
}
}