• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How child class call super class constructor..

 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Greenhorn
Posts: 19
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
raj talatam
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..
 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

raj talatam wrote:i tried cathyseira scjp, but they written in highlevel..


It's Kathy Sierra, BTW
 
Girish K Gupta
Greenhorn
Posts: 19
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi gupta,

They are asking questions on constructors, collections,

Exceptional handling

 
Good heavens! What have you done! Here, try to fix it with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic