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


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

Re: Why is it called "default constructor"?

Started byMike Amling <mamling@chaff.us>
First post2016-06-04 14:20 -0500
Last post2016-06-04 14:20 -0500
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.


Contents

  Re: Why is it called "default constructor"? Mike Amling <mamling@chaff.us> - 2016-06-04 14:20 -0500

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

FromMike Amling <mamling@chaff.us>
Date2016-06-04 14:20 -0500
SubjectRe: Why is it called "default constructor"?
Message-ID<niv9kh$poh$1@dont-email.me>
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=

[toc] | [standalone]


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


csiph-web