Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Default constructor?

 
Val Lee
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The default constructor invokes the no-parameter constructor of the superclass.
true or false?
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • 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
 
Anthony Villanueva
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
true
 
Amir Ghahrai
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic