Page 1 of 1

About Question enthuware.ocpjp.v7.2.1327 :

Posted: Wed Oct 29, 2014 3:38 pm
by jordanglassman
Which of the given options if put at //1 will correctly instantiate objects of various classes defined in the following code?
The wording of this question implied, to me, that it was asking for code that would instantiate *all* of the classes, but the answer is clearly looking for "1 or more".

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

Posted: Fri Oct 31, 2014 6:59 am
by admin
The options are clearly trying to instantiate exactly one class. So I am not sure how you go the impression that all classes need to be instantiated.
Also, the problem statement says "...objects of various classes..." and not "...objects of all classes..."
-Paul.

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

Posted: Wed Nov 12, 2014 6:46 am
by Veritas
minor typo in the explanation of option 3 (So an outer...)

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

Posted: Sat Sep 24, 2022 7:58 am
by sohamdatey22
Explanation Says:
"Although not related to this question, unlike popular belief, anonymous class can never be static. Even if created in a static method.",
Which seems to be misguiding, as the anonymous class declared as a member of a class can be static, the rule stated above only applies to anonymous class declared inside a method or a block, the instance member anonymous class can be static,

example :
interface A {
}
class Test {
static A a = new A(){};
}

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

Posted: Sat Sep 24, 2022 8:34 am
by admin
That's is not correct. In your example, the variable a is static, not the anonymous class.

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

Posted: Sat Sep 24, 2022 8:41 am
by sohamdatey22
....why is it not an anonymous class declaration??
We are implementing, the interface A here, just like we would do inside, a method, or static methods.
static A a = new A(){
};

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

Posted: Sat Sep 24, 2022 8:42 am
by sohamdatey22
ohh I think, i got you,
you are saying the class itself is not static, gotcha.

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

Posted: Mon Jan 16, 2023 3:36 am
by yuir12
Hello, question on option 5: new TestClass.C(); Suppose new TestClass().new C(), what is the concept behind mentioned methods being incorrect? Thanks!

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

Posted: Mon Jan 16, 2023 11:53 am
by admin
Sorry, I did not understand your question. Could you please describe more?

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

Posted: Tue Jan 17, 2023 1:15 am
by yuir12
Rephrasing: Why is new TestClass().new C() incorrect? Thanks

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

Posted: Tue Jan 17, 2023 1:32 am
by admin
Because class C is not a part of TestClass! It is local to the main method.
new TestClass().new C() implies that C exists in scope of TestClass, but that is not the case.

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

Posted: Tue Jan 17, 2023 5:03 am
by yuir12
oh got it, thanks.