About Question enthuware.ocpjp.v8.2.1179 :

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

Moderator: admin

Post Reply
ramy6_1
Posts: 124
Joined: Wed Feb 12, 2014 2:44 am
Contact:

About Question enthuware.ocpjp.v8.2.1179 :

Post by ramy6_1 »

Hello ,

Really am little bit confused about the question statement itself , what you mean by "Which of the following options can be a part of a correct inner class declaration or a combined declaration and instance initialization ?"

Kindly clarify.

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

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

Post by admin »

It is basically just asking you to identify the ones that can be valid inner class declarations. You can imagine an outer class and determine whether the given option can fit inside that class. For example :
class TestClass{
private class C { }// Option 1 is valid because it is indeed a valid inner class.
}

bstinch
Posts: 2
Joined: Thu Apr 21, 2016 8:10 pm
Contact:

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

Post by bstinch »

I don't understand why new SimpleInterface(){} is a valid answer. The question states SimpleInterface is an interface, so how is "new" used with an interface?

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

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

Post by admin »

The expression new SimpleInterface(){ } is valid because it is instantiating an anonymous class that implements SimpleInterface. It is not instantiating the interface.

Please go through this official tutorial for learning the basics of anonymous classes: https://docs.oracle.com/javase/tutorial ... asses.html

HTH,
Paul.

Mark7777
Posts: 32
Joined: Tue Apr 12, 2016 9:19 pm
Contact:

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

Post by Mark7777 »

Paul, I greatly admire your incredible depth of knowledge and all the help you are providing, especially at such reasonable prices. And I'm not trying to be difficult. Just wondering. How can I assume number 2 is an anonymous class if it doesn't end in a semi-colon. I studied the Oracle link you provided and all examples of anonymous class declarations end with a semi-colon. How am I not reading the question properly? Without the semicolon it looks like someone trying to instantiate an interface improperly, so I didn't chose it. What should have tipped me off that it was anonymous?

Dazed and confused, but humbly yours....

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

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

Post by admin »

The problem statement says, "...can be a part of a correct inner class declaration or a combined declaration and instance initialization". So, yes, a semi-colon at the end is missing, but other things such as an enclosing class, are missing as well. The given code is just a fragment, not a complete code listing and it can be a valid part of the complete code.

HTH,
Paul.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 5 guests