About Question enthuware.ocpjp.v7.2.1580 :

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

Moderator: admin

Post Reply
shamran99
Posts: 15
Joined: Wed May 10, 2017 2:49 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1580 :

Post by shamran99 »

The question is confusing. Actually the private member can only be accessed inside the class. But the private member of inner class can also be accessed by its outer class only after creating the inner class object.

From that its very clear that the class of an object x that can access reason is always should be InnerPeace.
Yes, OuterWorld has a public member of InnerPeace. But this makes no sense. Even now the outer class is depend on that InnerPeace object to access the reason.

cmPushkin
Posts: 1
Joined: Wed Nov 01, 2017 7:47 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1580 :

Post by cmPushkin »

The part "private member of inner class can also be accessed by its outer class only after creating the inner class object" clearly states that OuterWorld has access to 'reason'. It doesn't matter how.

This question is really confusing. x can be InnerPeace, but not ONLY as it states in third answer. it can be subclass of OuterWorld (if such subclass is inside OuterWorld class), but not ANY (outside OuterWorld class it has no access to 'reason'). It can't be any class in the same package or any class. So the only answer left is the second one.

gaurav.sjsu
Posts: 2
Joined: Sun Feb 11, 2018 11:48 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1580 :

Post by gaurav.sjsu »

I think only InnerPeace is the RIGHT answer. Let me tell you why?
1. reason is a private member of "InnerPeace" class. Hence it can not be accessed using a dot (.) operator even though you have an InnerPeace as a 'public' member of OuterWorld class.
2. When you explained that you can have a void m() method inside InnerPeace that allows you to access 'reason', your access from OuterWorld object, effectively, is to void m() method. Now, m() method has access to reason, which in turn, is inside InnerPeace class. Therefore the only class of an object that can have control over private member 'reason' will be InnerPeace.

Answer "Only InnerPeace." should have been the right answer.

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

Re: About Question enthuware.ocpjp.v7.2.1580 :

Post by admin »

You need to read the explanation carefully. It says, you can have a method m() inside OuterWorld, not InnerPeace. Like this:

Code: Select all

class OuterWorld
{
  public InnerPeace i = new InnerPeace();
  private class InnerPeace
  {  
   private String reason = "none";
  }
  void m(){
    System.out.println(i.reason);
  }
  
}
If you like our products and services, please help us by posting your review here.

yuir12
Posts: 22
Joined: Thu Dec 09, 2021 11:23 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1580 :

Post by yuir12 »

Hello.


Just wanted to ask why there is compilation error at //2?

Thanks

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

Re: About Question enthuware.ocpjp.v7.2.1580 :

Post by admin »

Are you sure you are trying out the code exactly as given?
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 23 guests