• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Marcus Green's exam 3, Q43

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which of the following statements are true
1) constructors cannot be overloaded
2) constructors cannot be overridden
3) a constructor can return a primitive or an object reference
4) constructor invocation occurs from the current class up the hierarchy to the ancestor class
I think that 4) is true also.
As I know, class's constructors always call the superclass's constructor (explicitly or implicitly). So, if you have class
Base and a SubBase class extends Base, the code like
SubBase sb = new SubBase(); will invoke super's constructor and then further up. Markus advises to print smth from the constructors to see what is an order of invocations. But, anyway the first line of any constructor should invoke super's constructor (the compiler does it if you missed it). It means that invocation goes up only. Just an example

No one argues about an order of printed lines
1) b method
2) a method
But, the matter is that aMethod invokes bMethod but not conversely.

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Java in a Nutshell" describes in some good detail "default no-args constructor chaining".
Obviously, the "invocations" are from the bottom up; the returns from the constructors in question are from the top down.
 
Nothing up my sleeve ... and ... presto! A tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic