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

Constructor overriding

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


can u explain y this type of output come here? Please explain.....
M.prints1, M.s1N.prints1, N.s1
 
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no overriding in the code since constructors, static methods and member variables cannot be overriden.

N() first calls M() which calls M.prints1() which uses M.s1 (output: M.prints1, M.s1). Then the body of N() is executed which calls N.prints1() (which prints N.prints1, N.s1).
 
Binesh Thusantha
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply Vlado Zajac.....

Can u explain why does N() call M()
 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Can u explain why does N() call M()



Whenever a constructor is called,it automatically calls its superclass constructor to finish the process of completing the creation of the object.

We can call it explicility by specifying super()(which makes call to the superclass constructor) otherwise JVM will call implicility.

Note:super() if present,should be the first line inside the constructor.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic