About Question enthuware.ocpjp.v7.2.1327 :

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

Moderator: admin

Post Reply
jordanglassman
Posts: 4
Joined: Tue Oct 28, 2014 2:11 pm
Contact:

About Question enthuware.ocpjp.v7.2.1327 :

Post 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".

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

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

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

Veritas
Posts: 12
Joined: Thu Aug 21, 2014 9:34 am
Contact:

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

Post by Veritas »

minor typo in the explanation of option 3 (So an outer...)

sohamdatey22
Posts: 28
Joined: Sun Sep 11, 2022 3:55 am
Contact:

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

Post 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(){};
}

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

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

Post by admin »

That's is not correct. In your example, the variable a is static, not the anonymous class.
If you like our products and services, please help us by posting your review here.

sohamdatey22
Posts: 28
Joined: Sun Sep 11, 2022 3:55 am
Contact:

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

Post 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(){
};

sohamdatey22
Posts: 28
Joined: Sun Sep 11, 2022 3:55 am
Contact:

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

Post by sohamdatey22 »

ohh I think, i got you,
you are saying the class itself is not static, gotcha.

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

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

Post 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!

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

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

Post by admin »

Sorry, I did not understand your question. Could you please describe more?
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.1327 :

Post by yuir12 »

Rephrasing: Why is new TestClass().new C() incorrect? Thanks

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

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

Post 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.
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.1327 :

Post by yuir12 »

oh got it, thanks.

Post Reply

Who is online

Users browsing this forum: No registered users and 32 guests