• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

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

 
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
because of at line 22
 
Ranch Hand
Posts: 633
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic