Code: Select all
Consider this class:
class A
{
private int i;
public void modifyOther(A a1)
{
a1.i = 20; //1
}
}
State whether the following statement is true or false:
At //1 a1.i is valid.
Isn't this question wrong?
Moderator: admin
Code: Select all
Consider this class:
class A
{
private int i;
public void modifyOther(A a1)
{
a1.i = 20; //1
}
}
State whether the following statement is true or false:
At //1 a1.i is valid.
Okay, I tested the code and it's working. Could you please explain in more details the statement "Private means private to the class and not to the object." ? As "a1" member is private, it should not accessible from object reference.Isn't it?admin wrote:No, it is correct. Why do you think it is wrong?
Thank you very much for the prompt response. This tool helps a lot to improve the knowledge as it explanations. Keep the awesome work. It's very helpful you guys can add more questions.admin wrote:That is why the explanation says that private means private to the class, not to the object. You can access i anywhere in class A even if the reference used to access i points to a different instance of class A.
Users browsing this forum: No registered users and 79 guests