java - What does the default constructor really do? -


there don't understand real role of default constructor in java. in official tutorial object creation :

creating objects

all classes have @ least 1 constructor. if class not explicitly declare any, java compiler automatically provides no-argument constructor, called default constructor. default constructor calls class parent's no-argument constructor, or object constructor if class has no other parent. if parent has no constructor (object have one), compiler reject program.

and in docs default constructor (§8.8.9)

8.8.9. default constructor

if class being declared the primordial class object, default constructor has empty body. otherwise, default constructor invokes superclass constructor no arguments.

so default constructor of class object has empty body. , know default constructor not initialize fields default values, because it's compiler :

default values

it's not necessary assign value when field declared. fields declared not initialized set reasonable default by compiler.

what don't understand is, if didn't declare constructor, what default constructor ?

what default constructor do?

it calls super(). per quotations. , nothing else. jls #8.8.9:

if class being declared primordial class object, default constructor has empty body. otherwise, default constructor invokes superclass constructor no arguments.

i.e. nothing else. believe initializes instance variables please see jls #12.5 contrary asserted.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -