Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #34467
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Mike Amling <mamling@chaff.us> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Why is it called "default constructor"? |
| Date | Sat, 4 Jun 2016 14:20:22 -0500 |
| Organization | A noiseless patient Spider |
| Lines | 40 |
| Message-ID | <niv9kh$poh$1@dont-email.me> (permalink) |
| References | <default-constructor-20160604183650@ram.dialup.fu-berlin.de> <default-constructor-20160604185253@ram.dialup.fu-berlin.de> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=windows-1252; format=flowed |
| Content-Transfer-Encoding | 8bit |
| Injection-Date | Sat, 4 Jun 2016 19:19:45 -0000 (UTC) |
| Injection-Info | mx02.eternal-september.org; posting-host="441da99360af715ca4185c982f638fb8"; logging-data="26385"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/m86Sd/vET4nzxgRCgDDPv" |
| User-Agent | Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0) Gecko/20100101 Thunderbird/45.1.1 |
| In-Reply-To | <default-constructor-20160604185253@ram.dialup.fu-berlin.de> |
| Cancel-Lock | sha1:zBToWquDWC+gadOPwX1XA7y8jCg= |
| Xref | csiph.com comp.lang.java.programmer:34467 |
Show key headers only | View raw
On 6/4/16 12:54 PM, Stefan Ram wrote:
> ram@zedat.fu-berlin.de (Stefan Ram) writes:
>> So, why is it called »default constructor«?
>
> We can read this in the JLS:
>
> |The declaration:
> |
> |public class Point {
> |int x, y;
> |}
> |
> |is equivalent to the declaration:
> |
> |public class Point {
> |int x, y;
> |public Point() { super(); }
> |}
> |
> |where the default constructor is public because the class
> |Point is public.
>
> So, it says that »public Point() { super(); }« is a »default
> constructor« in the second class declaration.
The second class declaration is a fiction whose only purpose is to
illustrate that the default constructor implicitly in the first class
declaration has no parameters and has 'super();' as its only statement.
> Therefore,
> »default constructor« can /not/ mean »used when no explicit
> declaration is given«, because in the second class
> declaration it /is/ given explicitly.
The second class declaration is not intended to be in a source file. The
second class declaration is just in our imaginations.
--Mike Amling
Tm90ZSB0aGF0IGEgbm9uLXN0YXRpYyBuZXN0ZWQgb3IgaW5uZXIgY2xhc3MgY29uc3RydWN0b3Ig
aGFzIG9uZSBvciBtb3JlIHBhcmFtZXRlcnMgbm90IHByZXNlbnQgaW4gdGhlIHNvdXJjZS4=
Back to comp.lang.java.programmer | Previous | Next | Find similar | Unroll thread
Re: Why is it called "default constructor"? Mike Amling <mamling@chaff.us> - 2016-06-04 14:20 -0500
csiph-web