惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
博客园_首页
H
Help Net Security
T
Tailwind CSS Blog
S
SegmentFault 最新的问题
GbyAI
GbyAI
Scott Helme
Scott Helme
D
Docker
Hacker News: Ask HN
Hacker News: Ask HN
P
Privacy & Cybersecurity Law Blog
Jina AI
Jina AI
雷峰网
雷峰网
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Spread Privacy
Spread Privacy
G
GRAHAM CLULEY
C
Cisco Blogs
The Hacker News
The Hacker News
F
Full Disclosure
Y
Y Combinator Blog
Blog — PlanetScale
Blog — PlanetScale
Recent Announcements
Recent Announcements
G
Google Developers Blog
量子位
K
Kaspersky official blog
Cisco Talos Blog
Cisco Talos Blog
The Cloudflare Blog
A
About on SuperTechFans
C
Cybersecurity and Infrastructure Security Agency CISA
Last Week in AI
Last Week in AI
博客园 - 三生石上(FineUI控件)
Microsoft Security Blog
Microsoft Security Blog
Martin Fowler
Martin Fowler
T
Tenable Blog
P
Palo Alto Networks Blog
H
Heimdal Security Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
W
WeLiveSecurity
Schneier on Security
Schneier on Security
The Register - Security
The Register - Security
F
Fortinet All Blogs
Stack Overflow Blog
Stack Overflow Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
The Blog of Author Tim Ferriss
N
News and Events Feed by Topic
Hugging Face - Blog
Hugging Face - Blog
小众软件
小众软件
V
V2EX
爱范儿
爱范儿

博客园 - Roland

几个基本的计算机概念 Silverlight 5几个不错的新特性 无光驱采用U盘安装完整版xp javascript 日期格式化(转) jQuery URL Parser 帮助 .net环境下的javascript引擎汇总 使用ANTLR进行命令行参数解析 使用VSTA定制二次开发IDE(一) 探讨Antlr中文文法与英文文法的差异 基础知识之vb.net的拷贝构造函数 垃圾回收浅谈 ASP.NET 页面对象模型[转自Msdnchina] dotnetnuke小结 dotnetnuke中皮肤管理小问题 DNN中令人困惑的用户管理机制 第一次学习dotnetnuke [转帖]怎样成为优秀的软件模型设计者? [转帖]论程序设计方法 让VFP回到旧时代
.net与java中关于访问性的差异
Roland · 2006-10-21 · via 博客园 - Roland

在.net下如下的代码是允许的
    class Program
    {
        static void Main(string[] args)
        {
            B b = new B();
            b.X = 20;
            b.Print(b);
            Console.ReadLine();
        }
    }

    class A {
        int x;
       public void Print(B b) {
            Console.Write(b.x); //可以通过编译
        }

        public int X {
            set {
                x = value;
            }
        }
    }

    class B : A { 
         public void Print(B b){
            Console.Write(b.x); //不可以通过编译
         }
    }
在这里的A类中可以访问B类中继承于A类的私有成员。
下面的是Java代码
public class A {
 private int x=0;
 public void Print(B b){
  System.out.println(b.x); // The field A.x is not visible 
   }
    public void setX(int value){
     x = value;
    }
 
 public void main(String[] args){
  B b = new B();
  b.setX(20);
  b.Print(b);
 }
}

class B extends A {
 
}
在Java中这样的访问是不允许的。