关键词搜索

源码搜索 ×
×

私有域

发布2014-09-04浏览2563次

详情内容

按道理,类中的私有域,外界不能访问,但是,对于同属一个类的对象,却可以访问,这一点,java和C#都是一样的。

java:

  1. public class Employee {
  2. private String name;
  3. public Employee(String name){
  4. this.name = name;
  5. }
  6. public boolean equals(Employee other){
  7. return name.equalsIgnoreCase(other.name);
  8. }
  9. }

name是私有域,但在这里,访问并无问题。

c#

  1. class Employee
  2. {
  3. private string name;
  4. public Employee(string name)
  5. {
  6. this.name = name;
  7. }
  8. public bool Equals(Employee other)
  9. {
  10. return (this.name.CompareTo(other.name) == 0);
  11. }
  12. }


相关技术文章

最新源码

下载排行榜

点击QQ咨询
开通会员
返回顶部
×
微信扫码支付
微信扫码支付
确定支付下载
请使用微信描二维码支付
×

提示信息

×

选择支付方式

  • 微信支付
  • 支付宝付款
确定支付下载