object TT { def main(args: Array[String]): Unit = { val clerk = new Clerk clerk.showInfo() Clerk.test(clerk) } } class Clerk { var name: String = "jack" private var sal: Double = 9999.9 protected var age = 10 var job: String = "大数据工程师" def showInfo(): Unit = { //在本类可以使用私有的 println(" name " + name + "n sal= " + sal) } } object Clerk { def test(c: Clerk): Unit = { //这里体现出在伴生对象中,可以访问c.sal println("test() name=" + c.name + "n sal= " + c.sal) } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)