java中的private到底有什么用

这是一个很古老的问题,记得我在进行面向对象的入门时曾向对此概念不是很清晰的同学解释过
不知楼主对结构有没有概念?(在此假设有)(当然了我的这一段文字的用意除了与楼主讨论外
也和其他朋友讨论)
1.写一个结构,给它起一个名字,在其内定义若干项数据
2.然后创建它的一个实例
3.可以通过先前创建的实例的名字.结构中某一项数据的名字 可以通过这样的一种方式来获得
或者改变这项数据
这第三步在C语言或VB中行得通,但在JAVA中却行不通了
在JAVA中
public class classOne
{
private int dataone;
private String datatwo;
...
private 自定义类型 datan;
}
classOne obj=new classOne();
obj.dataone=5;
具体说是这样就行不通了
在JAVA中通过对象点数据的方式行不通
因为数据是私有的,也就是在数据的前面加上了private 当然也可不定义为私有,但一般都是私有的(原因后面说)
所以就不能通过对象点的方式访问数据
现在来说说为什么要把数据定义为私有
把数据定义为私有通过公有方法来访问数据,这是一个规范
我们必须把数据定义为私有,因为我们必须要遵守规范!
我原来是玩.net的,后来改玩JAVA,很大的一个感触就是JAVA对.net要有规范
一个东西,在.net中很不经意,在JAVA中确有专门的名称,在.net中可以瞎编,完全不讲规范(虽然不提倡,但是确是可以的)
在JAVA中非但很困难甚至可以说不行.对此我很很深的感触.
所以在JAVA中编程是要讲规范了。除此之外用人的企业只怕也要讲规范.......
所以就让我们一起来遵守规范,从第一个在数据前面加上private,通过公有方法来访问数据开始吧!!!!

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值