访问控制符public ,private ,protected,private protected的区别!

访问控制符是一组限定类、域或方法是否可以被程序里的其他部分访问和调用的修饰符。具体地说,类及其属性和方法的访问控制符规定了程序的哪些其他部分可以访问和调用它们,哪些不可以。这里的其他部分是指程序里这个类之外的其他类,无论修饰符如何定义,一个类总能够访问和调用它自己的域和方法,但是这个类之外的其他部分能否访问这个类的域或方法,就要看该域和方法以及它所属的类的访问控制符了。

类的访问控制符只有一个 public 。

域和方法的访问控制符有四个,分别为 public 、 private 、 protected 、 private protected ,另外还有一种没有定义专门的访问控制符的缺省情况。

1. 公共访问控制符 public :如果一个类被声明为公共类,表明它可以被所有的其

它类所访问和引用。用 public 修饰的类的域称为公共域。如果公共域属于一个公共类,则它可以被所有的其他类所引用。

2. 私有访问控制符 private :用 private 修饰的成员变量 ( 域 ) 只能被该类自身所访

问,而不能被任何其它类 ( 包括子类 ) 所引用。

3. 保护访问控制符 protected :用 protected 修饰的成员变量可以被三种类所引用:

该类自身;与它在同一个包中的其它类;在其它包中的该类的子类。使用修饰符 protected 的主要作用是允许其它包中它的子类来访问父类的特定属性。

4. 私有保护访问控制符 private protected :用修饰符 private protected 修饰的成

员变量可以被该类本身或该类的子类两种类访问和引用。不论这些子类是与该类在同一个包里,还是处于其他的包中,相对于 protected , private protected 修饰符把同一包内的非子类排除在可访问的范围之外,使得成员变量更专用于具有明确继承关系的类,而不是松散地组合在一起的包。

5. 缺省访问控制符:如果一个类没有访问控制符,说明它具有缺省的访问控制符

特性。此时,这个类只能被同一个包中的类访问或引用。这一访问特性又称为包访问性。
 

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Network Security: Private Communication in a Public World, Second Edition By Charlie Kaufman, Radia Perlman, Mike Speciner ............................................... Publisher: Prentice Hall Pub Date: April 22, 2002 Print ISBN-10: 0-13-046019-2 Print ISBN-13: 978-0-13-046019-6 Web ISBN-10: 0-13-715588-3 Web ISBN-13: 978-0-13-715588-0 Pages: 752 Copyright The Radia Perlman Series in Computer Networking and Security Acknowledgments Chapter 1. Introduction Section 1.1. Roadmap to the Book Section 1.2. What Type of Book Is This? Section 1.3. Terminology Section 1.4. Notation Section 1.5. Primer on Networking Section 1.6. Active vs. Passive Attacks Section 1.7. Layers and Cryptography Section 1.8. Authorization Section 1.9. Tempest Section 1.10. Key Escrow for Law Enforcement Section 1.11. Key Escrow for Careless Users Section 1.12. Viruses, Worms, Trojan Horses Section 1.13. The Multi-Level Model of Security Section 1.14. Legal Issues Part 1: Cryptography Chapter 2. Introduction to Cryptography Section 2.1. What Is Cryptography? Section 2.2. Breaking an Encryption Scheme Section 2.3. Types of Cryptographic Functions Section 2.4. Secret Key Cryptography Section 2.5. Public Key Cryptography Section 2.6. Hash Algorithms Section 2.7. Homework Chapter 3. Secret Key Cryptography Section 3.1. Introduction Section 3.2. Generic Block Encryption Section 3.3. Data Encryption Standard (DES) Section 3.4. International Data Encryption Algorithm (IDEA) Section 3.5. Advanced Encryption Standard (AES) Section 3.6. RC4 Section 3.7. Homework Chapter 4. Modes of Operation Section 4.1. Introduction Section 4.2. Encry

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值