我有两个来自同一类的对象,称其为“第一”和“第二”。我有一个接受对象的方法,所以我使用“第一个”对象,调用该方法,将“第二个”对象传递给该方法。在该方法中,为什么我可以访问“第二个”对象的私有实例变量?我说的有道理吗?// Day.java, basic example of my questionpublic class Day{ private int stuff = 1; public Day(int stuff){ this.stuff = stuff; } public int m(Day d){ // This method takes in an object as a parameter int add = 0; add = this.day + d.day; // why can you do this? isn't "day" private? return add; }}
添加回答
举报
0/150
提交
取消