• 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
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Constructors and publication.

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If in some constructor Derived() i call a base class constructor Base() can I then always be sure that after
Derived derived = new Derived
when sharing derived between threads derived is either null or the Derived constructor has returnes ? I mean can it ever be that some other thread sees derived as having been initialized only by Base() ?
 
author
Posts: 23834
140
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Reiner Herman wrote:If in some constructor Derived() i call a base class constructor Base() can I ...



All derived class constructors call the base class constructors -- whether explicitely or implicitely.

Reiner Herman wrote:can I then always be sure that after
Derived derived = new Derived
when sharing derived between threads derived is either null or the Derived constructor has returnes ? I mean can it ever be that some other thread sees derived as having been initialized only by Base() ?



Think about it... how can an object be shared before it is returned from the new operator? The answer is that it can't.

Henry
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!