About 50 results
Open links in new tab
  1. function - Purpose of a constructor in Java? - Stack Overflow

    Nov 13, 2013 · What is the purpose of a constructor? I've been learning Java in school and it seems to me like a constructor is largely redundant in things we've done thus far. It remains to be seen if a …

  2. What's the difference between an object initializer and a constructor?

    Apr 11, 2009 · A constructor is a defined method on a type which takes a specified number of parameters and is used to create and initialize an object. An object initializer is code that runs on an …

  3. 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 …

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

    Apr 4, 2021 · As you can see, the constructor of the base class is called in the initialization list. Initializing the data members in the initialization list, by the way, is preferable to assigning the values …

  5. Can a struct have a constructor in C++? - Stack Overflow

    Sep 10, 2023 · In C++ the only difference between a class and a struct is that members and base classes are private by default in classes, whereas they are public by default in structs. So structs can …

  6. oop - Constructors in JavaScript objects - Stack Overflow

    Jul 11, 2009 · The function is invoked as a constructor when calling using new operator: ... Any instance or prototype object in JavaScript have a property constructor, which refers to the constructor …

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

    Apr 8, 2011 · An abstract class can have constructor and destructor. An abstract class cannot be a sealed class because the sealed modifier prevents a class from being inherited.

  8. Can constructors throw exceptions in Java? - Stack Overflow

    Sep 3, 2009 · Yes, constructors can throw exceptions. Usually this means that the new object is immediately eligible for garbage collection (although it may not be collected for some time, of …

  9. C++: Where to initialize variables in constructor - Stack Overflow

    Apr 16, 2015 · If you do not mention a variable in a class's initialization list, the constructor will default initialize it before entering the body of the constructor you've written. This means that option 2 will …

  10. Is there a difference between a “constructor” and a “constructor ...

    Obj is now the constructor of the instance obj. Obj is just a normal function, but since it's invoked via new it acts as a constructor. Note that constructor functions are by convention named like Java classes, …