scala学习笔记(二)

来源:互联网 发布:python中sleep函数 编辑:程序博客网 时间:2024/03/28 20:41

    class Person private (val name:String, val age:Int){ //括号中的就是主构造器,加了private就不能使用主构造器了。        print("i am a part of main constructor")        private var name =""        private var age = 0        def this(name:String){ //一个辅助构造器            this()            this.name=name        }    }

枚举

object TrafficLightColor extends Enumeration{    val TrafficLightColor =Value    val Red, Yellow, Green = Value}
0 0