[Java]private, the difference between public,protected,friendly (reprint) Remember all of a sudden

Source: Internet
Author: User

http://teddyboy200382.blog.163.com/blog/static/320112002008825112549780/

Description of these four keywords before I want to justClassTo make a simple definition of the relationship, for the inheritance of their ownClass,Base classcan be thought of as their own children, and for a directory of their ownClasses, thinking they are all their friends.

1,Public:public indicates that the data member, member function is open to all users, and all users can call
 < Span lang= "en-US" >2, private : private means private, private means except class No one else can use it directly, and private property is inviolable, even for children and friends.
 3, protected: protected , free to use without any restrictions, and for other external classprotected private

4,friendly: do not write when the default is friendly,friendly is friendly, for friends, Can be used freely, without any restrictions, and for other external classes, even children, can not be used .

Scope Current class same package descendant class other package

Public√√√√

Protected√√√x 

friendly       √            √             x            x 

private         √             x             x             x

[Java]private, public,protected,friendly difference (reprint) Remember all at once

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.