我有兩個(gè)來(lái)自同一類的對(duì)象,稱其為“第一”和“第二”。我有一個(gè)接受對(duì)象的方法,所以我使用“第一個(gè)”對(duì)象,調(diào)用該方法,將“第二個(gè)”對(duì)象傳遞給該方法。在該方法中,為什么我可以訪問(wèn)“第二個(gè)”對(duì)象的私有實(shí)例變量?我說(shuō)的有道理嗎?// 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; }}
添加回答
舉報(bào)
0/150
提交
取消