Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #34467
| From | Mike Amling <mamling@chaff.us> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Why is it called "default constructor"? |
| Date | 2016-06-04 14:20 -0500 |
| Organization | A noiseless patient Spider |
| 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> |
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