Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #36691 > unrolled thread
| Started by | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| First post | 2017-06-21 12:52 -0400 |
| Last post | 2017-06-21 12:52 -0400 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.java.programmer
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: "default constructor" Arne Vajhøj <arne@vajhoej.dk> - 2017-06-21 12:52 -0400
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2017-06-21 12:52 -0400 |
| Subject | Re: "default constructor" |
| Message-ID | <oie891$ome$1@gioia.aioe.org> |
On 6/18/2017 9:49 PM, Stefan Ram wrote: > A default constructor is a constructor that misses something. > > In C++, it is a constructor that can be called with missing > arguments (no arguments). > > C++ 12.1p4: > > A default constructor for a class X is a constructor of > class X for which each parameter that is not a function > parameter pack has a default argument (including the > case of a constructor with no parameters). > > In Java, it is a constructor that is generated when an > explicit constructor declaration is missing. The generated > constructor just so happens to have no parameters, but > an explicitly declared constructor with no parameters is > not a default constructor, but replaces it: > > JLS8 13.4.12 > > Adding one or more constructor declarations to the > source code of such a class will prevent this default > constructor from being implicitly declared, effectively > deleting a constructor, unless one of the new > constructors also has no parameters, thus replacing the > default constructor. > > Summary (simplified): In C++, "default constructor" means > "any constructor that does not require an argument". > In Java, it means "the constructor that is generated if > the user does not declare any constructor". So? C++ and Java are two different languages. They also have somewhat different associated terminologies. No surprise. Arne
Back to top | Article view | comp.lang.java.programmer
csiph-web