Page 1 of 1

About Question enthuware.ocpjp.v8.2.1135 :

Posted: Mon Jul 18, 2016 8:47 am
by RAZER-KIEV
How it can correctly instantiate "TestInner" object from Line 1 if the code never calls myOuterMethod() ?

Re: About Question enthuware.ocpjp.v8.2.1135 :

Posted: Mon Jul 18, 2016 11:09 am
by admin
It is true that the code that is given with the question doesn't call myOuterMethod(). But that is not really required. It is a public method and it could be called from any other class.

HTH,
Paul.

Re: About Question enthuware.ocpjp.v8.2.1135 :

Posted: Mon Jul 18, 2016 11:55 am
by RAZER-KIEV
imho it looks like ambiguously.
1) There is no any information about other classes. So we have no any guaranty that it will be called from somewhere.
2) The existing and content of psvm method shows that there is not any "// lot of another code" so this is enough to think that this is completely content of psvm. So I can say that it is impossible to call myOuterMethod() from anywhere. Am I wrong?

Re: About Question enthuware.ocpjp.v8.2.1135 :

Posted: Mon Jul 18, 2016 12:07 pm
by admin
The question is only talking about the lines of code that instantiate TestInner correctly. That is why it says, "instantiates" i.e. "Which of the following options correctly instantiates a TestInner object?" The given line of code in option 1 does correctly instantiate TestInner. Of course, instantiation will happen if it is invoked, but that is not part of the question. The question doesn't say if or whether TestInner is instantiated by the given code listing if the given program is compiled and executed. It doesn't even talk about running/executing the code. So from that perspective, even the main method is not executed.



HTH,
Paul.

Re: About Question enthuware.ocpjp.v8.2.1135 :

Posted: Mon Jul 18, 2016 12:37 pm
by RAZER-KIEV
I can say that anything what located in myOuterMethod() will never be invoked, because we can observe psvm method which doesn't invokes it. As Application can't have one more psvm we can say that myOuterMethod never be called. If there was any other static method but not main, the options 1 and 5 would be correct. I understand that focus of this question was on other aspect, but we cant ignore that where is enough information to be sure that there are no places from where we can call myOuterMethod.

Re: About Question enthuware.ocpjp.v8.2.1135 :

Posted: Mon Jul 18, 2016 1:49 pm
by RAZER-KIEV
I was wrong !)
There can be more than one public static void main, in one application. So we can create another class with psvm where we can invoke "new TestOuter().myOuterMethod();" and it will work fine)
So option 1 and 5 are really correct.
Thanks for discussion)