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.
About Question enthuware.ocpjp.v8.2.1179 :
Moderator: admin
-
- Posts: 124
- Joined: Wed Feb 12, 2014 2:44 am
- Contact:
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1179 :
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.
}
class TestClass{
private class C { }// Option 1 is valid because it is indeed a valid inner class.
}
-
- Posts: 2
- Joined: Thu Apr 21, 2016 8:10 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1179 :
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?
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1179 :
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.
Please go through this official tutorial for learning the basics of anonymous classes: https://docs.oracle.com/javase/tutorial ... asses.html
HTH,
Paul.
-
- Posts: 32
- Joined: Tue Apr 12, 2016 9:19 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1179 :
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....
Dazed and confused, but humbly yours....
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1179 :
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.
HTH,
Paul.
Who is online
Users browsing this forum: No registered users and 3 guests