我有兩個來自同一類的對象,稱其為“第一”和“第二”。我有一個接受對象的方法,所以我使用“第一個”對象,調(diào)用該方法,將“第二個”對象傳遞給該方法。在該方法中,為什么我可以訪問“第二個”對象的私有實例變量?我說的有道理嗎?// 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
提交
取消