Understanding of package, class, object, member access rights in Scala

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.