wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes why does method get called twice though it is called only once? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "why does method get called twice though it is called only once?" Watch "why does method get called twice though it is called only once?" New topic
Author

why does method get called twice though it is called only once?

maggie karve
Ranch Hand

Joined: Dec 29, 2009
Posts: 186
here first superclass constructor is called then it invoked method of subclass then again subclass constructor is called then why again the method is called though i didnt call the method in subclass constructor???
i expected the output to be
A1
null0falsename age and values are printed
Checking
but the output is A1
null0falsename age and values are printed
Checking
abc12truename age and values are printed
Rajiv Chopra
Ranch Hand

Joined: Dec 19, 2008
Posts: 62
because of at line 22


Rajeev Kumar
SCJP 6.0 Certified 96%
Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Posts: 629

when you write


then constructor of subclass is called which call constructor of super class i.e A1() which prints

then this constructor call show method which prints



after super class constructor completes subclass constructor i.e(class Checking ) constructor runs and prints


After completing subclass constructor you call method show() which prints


Life is easy because we write the source code.....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why does method get called twice though it is called only once?
 
Similar Threads
Clone problem
Confusion with startElement,endElement and characters method
Constructor doubt
Puzzling Dan Chisholm question on inner classes
Core Java Basic