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


Groups > comp.lang.java.programmer > #34479

Re: Why is it called "default constructor"?

Newsgroups comp.lang.java.programmer
Date 2016-06-05 09:35 -0700
References <default-constructor-20160604183650@ram.dialup.fu-berlin.de> <nivd65$pnn$1@dont-email.me>
Message-ID <06d7e459-4001-4c07-a2bd-cf811fb1e58a@googlegroups.com> (permalink)
Subject Re: Why is it called "default constructor"?
From Lew <lewbloch@gmail.com>

Show all headers | View raw


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

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

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

csiph-web