object Test { def main(args: Array[String]): Unit = { val a1 = new tt //实例化对象 println(a1.a) a1.f(2) println(a1.a) println(a1) }}//定义一个类叫ttclass tt{ var a = 0 //成员变量a def f(b:Int):Int = { a=a+b return a } override def toString = s"tt($a)" //toString方法}