In this paper, the following program is a simple analysis of the package, class, object access to the situation:
Package spark { package navigation { private[spark] class Navigator { protected[navigation] def Usestartchar () = println ("Navigation") class legofjourney { private[Navigator] val distance = 100 } private[this] var speed = 200 } class test{ new navigator (). Usestartchar () } } package launch { object Vehicle { private[launch] val guide = new navigation. navigator } }}
First analysis of the above program, the spark package has two packets navigation and launch, in the package navigation inside the Class navigator defined, and its access rights to upgrade to all under the spark package, meaning that in the spark package can access the class,
The following bread launch inside is visited by the class Navigator,private[launch] Val guide = new navigation. Navigator.
Method Usestartchar () is defined in class Navigator and its access permission is set to navigation, which indicates that the method can only be accessed within the package navigation, such as New Navigator () in the test class. Usestartchar ()
Private[this] var speed = 200, this can only be accessed in Class Navigator, and can no longer be accessed in other class objects of that class.
This article is from "Dt_spark Big Data DreamWorks" blog, please make sure to keep this source http://18610086859.blog.51cto.com/11484530/1774371
Understanding of package, class, object, member access rights in Scala