Page 1 of 1
About Question enthuware.ocpjp.v8.2.1179 :
Posted: Wed Aug 24, 2016 9:19 am
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.
Re: About Question enthuware.ocpjp.v8.2.1179 :
Posted: Wed Aug 24, 2016 9:34 pm
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.
}
Re: About Question enthuware.ocpjp.v8.2.1179 :
Posted: Sun Oct 02, 2016 2:40 pm
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?
Re: About Question enthuware.ocpjp.v8.2.1179 :
Posted: Sun Oct 02, 2016 9:05 pm
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.
Re: About Question enthuware.ocpjp.v8.2.1179 :
Posted: Wed Oct 24, 2018 8:39 pm
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....
Re: About Question enthuware.ocpjp.v8.2.1179 :
Posted: Wed Oct 24, 2018 9:03 pm
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.