About 50 results
Open links in new tab
  1. When is it right for a constructor to throw an exception?

    The constructor's job is to bring the object into a usable state. There are basically two schools of thought on this. One group favors two-stage construction. The constructor merely brings the object into a …

  2. C# : assign data to properties via constructor vs. instantiating

    Oct 2, 2013 · Object initializers let you assign values to any accessible fields or properties of an object at creation time without having to explicitly invoke a constructor.

  3. function - Purpose of a constructor in Java? - Stack Overflow

    Nov 13, 2013 · A constructor is used to create an instance of the class Card. And you'll need to call it 52 times to have 52 cards: new Card(1, "hearts"), etc. Now each instance of Player (you also need a …

  4. Constructor of an abstract class in C# - Stack Overflow

    Mar 15, 2015 · An abstract class constructor c# code example will be explained. But, the next question can also be arises, as if we cannot instantiate (construct an object using new) an abstract class, then …

  5. C++, What does the colon after a constructor mean?

    May 7, 2010 · An initializer list is how you pass arguments to your member variables' constructors and for passing arguments to the parent class's constructor. If you use = to assign in the constructor …

  6. oop - Constructors in JavaScript objects - Stack Overflow

    Jul 11, 2009 · Using Nick's sample above, you can create a constructor for objects without parameters using a return statement as the last statement in your object definition.

  7. constructor - C# member variable initialization; best practice? - Stack ...

    May 27, 2015 · One can then avoid calling the constructor except through factory methods which in case of exception will call Dispose on the partially-created object. This protection will allow for cleanup of …

  8. How to initialize a list with constructor? - Stack Overflow

    Feb 1, 2012 · Please guide me is among best practices to use constructor with for list initialization? How to assign values to list using a constructor, so if no value passed a default will be used?

  9. What are the rules for calling the base class constructor?

    Apr 4, 2021 · 1189 Base class constructors are automatically called for you if they have no argument. If you want to call a superclass constructor with an argument, you must use the subclass's constructor …

  10. Can I call a constructor from another constructor (do constructor ...

    Nov 21, 2008 · When calling a constructor it actually allocates memory, either from the stack or from the heap. So calling a constructor in another constructor creates a local copy.