Author Topic:   Inner class Constructor
Shiva
ranch hand
posted April 07, 2000 03:05 PM         
this is a question from javaworld
1. Given the following class definition:

class A
{
protected int i;
A(int i)
{
this.i = i;
}
}

Which of the following would be a valid inner class for this class? Select all valid answers.

A.class B {}

B.class B extends A {}

C.class B
{
B()
{
System.out.println("i = " + i);
}
}

D.class B
{
class A {}
}

E.class A {}


Ans: a) and c)

IMO there is no default (no arg) constructor in class A

then how come ans c) is correct? constructor in class B which is also no arg constructor will try to call default constructor in A? then why ans b) is wrong??

Maha , Jim i need your help here,
thank you


------------------

[This message has been edited by maha anna (edited April 07, 2000).]

maha anna
bartender
posted April 07, 2000 03:22 PM             
Shiva,
Please use the formating tags [ code ] [ /code] around your sample code. Or you can use the html tags < pre> < /pre> all tags without the space inside them.

The ans. given are correct and your thinking is also correct. But you didn't apply it properly I think. Please read the ans carefully. ans b) is wrong because this is the one which extends class A and needs the A() in A class. Since it is not there in A, this ans is wrong.
Ans c) is correct because This is just an ordinaryinner class which does not extend A. It is perfectly fine.

Please refer to this. I also request all to use the 'search' facility liberally at the top-right of every page.
regds
maha anna

[This message has been edited by maha anna (edited April 07, 2000).]

Shiva
ranch hand
posted April 07, 2000 03:40 PM         
thank you maha,
i didnt know about those formatting tags, will use from now onwards and i think now i am clear on constructors

|