• Post Reply Bookmark Topic Watch Topic
  • New Topic

Constructors and publication.  RSS feed

 
Reiner Herman
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() ?
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor 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!