The difference between class and object

1, the difference between class and object

calss scala compiler will help us produce a field private field and two public methods get and set

scala no static keyword, so for a class, all the member variables and methods are inaccessible before the new instance is out

Therefore, the main method in the class of no use

scala the object of all the member variables and methods are static default of

It is possible to directly access the main method

class Lis {
  age var = 19 And
}
object Test{
  def main(args: Array[String]): Unit = {
    There s = new Lisa
    s.age=10    //set
    println(s.age)  //get
  }
}

 

Reference blog: https://blog.csdn.net/weixin_34144848/article/details/85809919

Guess you like

Origin www.cnblogs.com/guoyu1/p/12122715.html