object helloWorld {
def main(args: Array[String]): Unit = {
println("Hello World")
}
}
object :关键字,生成一个单例对象(没有上来就定义一个类class),底层实际隐藏了这个类的创建,这个对象也称为伴生对象(随着类的产生而产生helloworld.calss,这个类也称为伴生类), main:主函数入口 args: Array[String]:参数名及类型,类型在:后,而不是像java 类型在前 Unit:返还值为空,类似void
运行这段helloWorld 底层会生成两个.class文件
object 伴生对象对应helloworld$.class,helloworld.class对应的伴生类