Can one object access a private variable of another object of the same class? Answer is given yes. But I couldn't understand the question. How can one object access other object's private variable? Please give me an example code.
Good answer, Marc. I had a couple of students confused by this just yesterday. The example code was:
The most common answer to this is that student's tend to gloss over the point that b needs to access a's private data. Some catch it and say that the code won't compile. Sadly, the ones with the sharper eyes are wrong. Access modifiers are at the class level, not the object level.
[ June 01, 2007: Message edited by: Bill Cruise ]
[ June 01, 2007: Message edited by: Bill Cruise ] [ June 01, 2007: Message edited by: Bill Cruise ]