About Question com.enthuware.ets.scjp.v6.2.676 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
aruna1982
Posts: 5
Joined: Sat Feb 15, 2014 4:31 pm
Location: Singapore
Contact:

About Question com.enthuware.ets.scjp.v6.2.676 :

Post by aruna1982 »

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.
Explanation said "Private means private to the class and not to the object."

Isn't this question wrong?

admin
Site Admin
Posts: 10046
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question com.enthuware.ets.scjp.v6.2.676 :

Post by admin »

No, it is correct. Why do you think it is wrong?
If you like our products and services, please help us by posting your review here.

aruna1982
Posts: 5
Joined: Sat Feb 15, 2014 4:31 pm
Location: Singapore
Contact:

Re: About Question com.enthuware.ets.scjp.v6.2.676 :

Post by aruna1982 »

admin wrote:No, it is correct. Why do you think it is wrong?
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
Site Admin
Posts: 10046
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question com.enthuware.ets.scjp.v6.2.676 :

Post by admin »

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.
If you like our products and services, please help us by posting your review here.

aruna1982
Posts: 5
Joined: Sat Feb 15, 2014 4:31 pm
Location: Singapore
Contact:

Re: About Question com.enthuware.ets.scjp.v6.2.676 :

Post by aruna1982 »

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.
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.
Thanks.

Post Reply

Who is online

Users browsing this forum: No registered users and 79 guests