File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

INNER CLASS

 
sheri
Ranch Hand
Posts: 43
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10065
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Anonymous
Ranch Hand
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 28
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3141
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.)

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic