Go language Learning (14) object-oriented programming-visibility

Source: Internet
Author: User
This is a created article in which the information may have evolved or changed.

The go language is very stingy with the addition of keywords, where there is no key to private, protected, public
Word. To make a symbol visible to other packages (that is, accessible) you need to define the symbol as an uppercase letter
The beginning, such as:

typestruct {    float64    float64}

In this way, the member variables of the RECT type are all exported and can be accessed by all other code referencing the package where the RECT resides.

The accessibility of member methods follows the same rules, such as:

funcfloat64 {    return r.Width * r.Height}

In this way, the area () method of Rect can only be used within the same package as the type.

One thing to note is that the accessibility of symbols in the go language is at the package level rather than at the type level. In the example above
Child, although area () is an internal method of rect, it can also be accessed by other types in the same package. This can be
Access control is very rough, very special but very practical.

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.