Hello,
I came across this question on Ranch Roundup Game as shown below
Can one object access private variable of another object of the same class ?
a) Yes
b) No
The answer is Yes.
The explanation given is: Private means "private to the class", NOT "private to the object" . So two objects of the same class could access each others private data.
***********************************************************************
My interpretation for the above question was as follows
public class Employee {
private int salary;
public static void main (
String [] args){
Employee emp1 = new Employee();
emp1.salary = 1000;
Employee emp2 = new Employee();
/*How can one write a code here using emp2 object and modify the emp1.salary which is private data of object emp1.*/
}
}
May be my interpretation of the question is wrong ? Gurus help me !!!
Cheers
Jay