Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Initialization

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Can you please correct me on the following point if I am wrong.
Constructor is provided by the compiler only if the class does not define any constructor and it calls the default 'no-args' constructor of the super class.
However constructor does not initialize instance members and class ( static ) members of the class.
This initialization is done by 'new' statement at the time of creation of object.
Regards
Sandip

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Constructor is provided by the compiler only if the class does not define any constructor


Yes, a default no argument constructor is provided in this case.

it calls the default 'no-args' constructor of the super class.


This is trickier. Basically, if the first line of the constructor is not a this(..) or super(..), then a super() call is inserted implicitly.


However constructor does not initialize instance members and class ( static ) members of the class. This initialization is done by 'new' statement at the time of creation of object.


Well, first, to get the semantics right, the constructor doesn't really do anything. This is what happens in the larger scheme of things. A class is loaded, its static initializers are called, the constructor is called, instance initializers are executed, the rest of the constructor is run. If a superclass comes into the picture, things get even trickier. The point to remember is the superclass is initialized before the class (that means its static, instance initializers and constructor are called before their subclass counterparts).
 
Good night. Drive safely. Here's a tiny ad for the road:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic