File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
maggie karve
Ranch Hand
Posts: 187
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 62
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
because of at line 22
 
Pramod P Deore
Ranch Hand
Posts: 632
Android Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic