wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes INNER CLASS Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "INNER CLASS " Watch "INNER CLASS " New topic
Author

INNER CLASS

sheri
Ranch Hand

Joined: Sep 14, 2000
Posts: 43
Which are a part of a correct inner class declaration or a combined declaration and instance initialization

A. private MyInner {
B. new SimpleInterface() {
C. new ComplexInterface(x) {
D. private final abstact class C
E. new ComplexClass() implements SimpleInterface
MY ANS ARE:A,B,C
NOT SURE IF OPTION C IS CORRECT,PLS CORRECT ME IF I AM WRONG

2: What snippet can be a part of a declaration of an inner class: (select all)
A. private MyInner {
B. new myInner() extends OtherClass {
C. static class MyInner {
D. abstract class MyInner {
MY ANS ARE:A,C,D
Which are valid declarations :
a. private class A
b. class X extends Y { // Note the {
ANS ARE:A,B
I AM APPEARING FOR THE EXAM BY THIS SATURDAY
HELP PLS
THANX
SHERIN
Mapraputa Is
Leverager of our synergies
Sheriff

Joined: Aug 26, 2000
Posts: 10065
Hi sheri!
If �combined declaration and instance initialization� means that class is anonimous (and I think so)
than
C) new ComplexInterface(x) {
is incorrect, because anonimous inner classes cannot have a constructor, which could take parameter x.
If option C were coded as
C) new ComplexInterface() {
- it would be correct

Uncontrolled vocabularies
"I try my best to make *all* my posts nice, even when I feel upset" -- Philippe Maquet
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi sheri;
Here is my answers:
Which are a part of a correct inner class declaration or a combined declaration and instance initialization
A. private MyInner {
B. new SimpleInterface() {
C. new ComplexInterface(x) {
D. private final abstact class C
E. new ComplexClass() implements SimpleInterface
Answers: B,C
A is incorrect since it misses the keyword class in the declaration.
2: What snippet can be a part of a declaration of an inner class: (select all)
A. private MyInner {
B. new myInner() extends OtherClass {
C. static class MyInner {
D. abstract class MyInner {
Answers: C,D

Thanks,
Erin
geetha
Greenhorn

Joined: Jun 27, 2001
Posts: 15
Originally posted by Mapraputa Is:
Hi sheri!
If �combined declaration and instance initialization� means that class is anonimous (and I think so)
than
C) new ComplexInterface(x) {
is incorrect, because anonimous inner classes cannot have a constructor, which could take parameter x.
If option C were coded as
C) new ComplexInterface() {
- it would be correct

Hi,
if the annonymous class is extending from any class which has a constructor then the ans C would be correct.here he didn't mention that complexinterface is an interface or a class.ofcourse there is a clue that it can be an interface but we are not sure whether that is extending from class or interface in which case I would say C is also correct ans.
geetha

ramani2020
Greenhorn

Joined: Sep 14, 2000
Posts: 28
hi geetha,
But anonymous classes, by definition, dont have a constructor or a name.
If the class extends another class which has a constructor, the inner class is not anonymous ..am I right? or am I missing something?
could you give an example ?
or,could you tell me what modifications are to be made to convert the foll into an anonymous class like you said, extending from class father, and without a name..

thanks in advance,
Ramani.


Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Hi Ramani,
I played with your code and think this is an example of using an anonymous class (please let me know if I'm wrong).
I changed the original to use main() instead of Applet and I had to put a call in the 'father' constructor to access method() (is there a way to directly invoke a parent method from an Anonymous class? I could not find any code examples.)


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: INNER CLASS