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

Default constructor?

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The default constructor invokes the no-parameter constructor of the superclass.
true or false?
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Val Lee:
The default constructor invokes the no-parameter constructor of the superclass.
true or false?


True.
Of course, all constructors invoke the no-parameter constructor of the superclass unless a call to a different constructor is made explicitly through the use of the keyword super.
Corey
 
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
true
 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's true, but not only the default constructor in the subclass does this. Even if you have a non-default constructor in your sub-class, it will still call the default constructor of the supper class, unless you specify the correct signature of the non-default constructor of the super-class (if there are any) in the constructor of the subclass.
take this example:

e.g

HTH
Edited by Corey McGlone: Broke up the long comment into multiple lines for better display.
[ July 11, 2002: Message edited by: Corey McGlone ]
 
Amir Ghahrai
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
guys sorry about the messup of putting a long text inside the brackets. didn't realize the side-effect!
 
Val Lee
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From the JLS,�8.8.7 Default Constructor

A compile-time error occurs if a default constructor is provided by the compiler but the superclass does not have an accessible constructor that takes no arguments.


So I think it is false.
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Val Lee:
From the JLS,�8.8.7 Default Constructor

So I think it is false.


Huh?
That statement says that a compiler error occurs if the superclass doesn't have an accessible no-args constructor. This would only be an error is the default constructor tried to invoke the no-args constructor.
Therefore, this statement is proving the fact that a default constructor invokes the no-args constructor of the superclass, not the other way around.
Try this:

Corey
 
Anthony Villanueva
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Amir yaar what have you done?

Well, I never liked splitting hairs, but IMHO the question was if the superclass constructor will be invoked, not if the invocation was actually successful.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic