Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #34472 > unrolled thread

Re: Why is it called "default constructor"?

Started byEric Sosman <esosman@comcast-dot-net.invalid>
First post2016-06-04 16:20 -0400
Last post2016-06-05 09:35 -0700
Articles 2 — 2 participants

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.


Contents

  Re: Why is it called "default constructor"? Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-06-04 16:20 -0400
    Re: Why is it called "default constructor"? Lew <lewbloch@gmail.com> - 2016-06-05 09:35 -0700

#34472 — Re: Why is it called "default constructor"?

FromEric Sosman <esosman@comcast-dot-net.invalid>
Date2016-06-04 16:20 -0400
SubjectRe: Why is it called "default constructor"?
Message-ID<nivd65$pnn$1@dont-email.me>
On 6/4/2016 1:39 PM, Stefan Ram wrote:
>   When a constructor is implicitly declared, it often has no
>   parameters and it often is called »default constructor«.
>
>   »Default« means »used when something is missing«.

     Like, for example, a constructor you didn't write.  Every
class requires a constructor, so if you don't write one it is
missing.

>   So, why is it called »default constructor«?

     Because it's the constructor the compiler writes for you in
the event you fail to write any yourself.

-- 
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM

[toc] | [next] | [standalone]


#34479

FromLew <lewbloch@gmail.com>
Date2016-06-05 09:35 -0700
Message-ID<06d7e459-4001-4c07-a2bd-cf811fb1e58a@googlegroups.com>
In reply to#34472
On Saturday, June 4, 2016 at 1:20:31 PM UTC-7, Eric Sosman wrote:
> On 6/4/2016 1:39 PM, Stefan Ram wrote:
> >   When a constructor is implicitly declared, it often has no
> >   parameters and it often is called »default constructor«.
> >
> >   »Default« means »used when something is missing«.
> 
>      Like, for example, a constructor you didn't write.  Every
> class requires a constructor, so if you don't write one it is
> missing.
> 
> >   So, why is it called »default constructor«?
> 
>      Because it's the constructor the compiler writes for you in
> the event you fail to write any yourself.

A corollary is that if you write a no-argument, no-throws constructor that only (implicitly or explicitly) calls 'super()' and does nothing else, of the same access level as the class, then it is not a default constructor.

-- 
Lew

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web