| Author |
How child class call super class constructor..
|
raj talatam
Ranch Hand
Joined: Apr 19, 2012
Posts: 59
|
|
i attended an interview they have given this question
what is out put for this question ,
i thought when we compile the child class , and decompile the child class by using javap,
,compiler will provide only provide only defaukt constructor if not provided one,
thats what i understand ed from javap, by seeing the byte code
but the output is different , it is calling super class constructor,
there is no signs of calling super class constructor in the byte code of Child class,
then how it is possible to call super class constructor
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
use javap -c YourClass
1: invokespecial #11; //Method java/lang/Object."<init>":()V
you will see the above statement in constructor. which is nothing
but call default constructor of your super class.
Shortly, compiler insert super() to first line of your every constructor, if you dont provide super(...) or this(...) explicitly
|
 |
Girish K Gupta
Greenhorn
Joined: Mar 14, 2007
Posts: 19
|
|
Hi Raj
These are standard questions with constructor-chaining concept.
In all constructors a call to super classes's constructor is implicitly made.
eg, If you write parent's constructor as following:
It would be interpreted like:
Please see the documentation http://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.8
You can refer to any Java text book as well.
Regards
|
Girish K Gupta
SCJP 1.5 - 87%, SCWCD 1.5 - 92%
India
|
 |
raj talatam
Ranch Hand
Joined: Apr 19, 2012
Posts: 59
|
|
Thanks for , your replie
Then why cant we see ,this super class constructor,in byte code
by using javap conmmand because it is profiler right( decompiler),
is there any plugins for decompiler, in eclipse
or any software for decompiling, please suggest that software,
And last thing ,these are standard questions which i am facing in interviews,
can any one please suggest, how solve this type of questions,
or books are there to pratice this type of question,
i tried cathyseira scjp, but they written in highlevel..
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32708
|
|
raj talatam wrote: . . . Then why cant we see ,this super class constructor,in byte code . . .
Yes, you can. Seetharaman Venkatasamy showed you it: Object."<init>".
When you are asked that sort of question, remember that such implementation details are not necessary for the programmer to know.
|
 |
John Jai
Bartender
Joined: May 31, 2011
Posts: 1778
|
|
raj talatam wrote:i tried cathyseira scjp, but they written in highlevel..
It's Kathy Sierra, BTW
|
 |
Girish K Gupta
Greenhorn
Joined: Mar 14, 2007
Posts: 19
|
|
Hi Raj
I don't know what types of questions you are looking for but for the one you mentioned in this thread above the Kathy Siera book gives all the required information.
I feel whatever is provided in this book is more than sufficient for an application developer. [Chapter 2, Constructors and Instantiation (Exam Objectives 1.6, 5.3, and 5.4)]
|
 |
raj talatam
Ranch Hand
Joined: Apr 19, 2012
Posts: 59
|
|
Hi gupta,
They are asking questions on constructors, collections,
Exceptional handling
|
 |
 |
|
|
subject: How child class call super class constructor..
|
|
|