Default constructor
From Wikipedia, the free encyclopedia
A default constructor is a constructor that can be called with no arguments. [1] In Java, a default contructor can be used only if there are no explicitly defined ones.
C++ defines two special kinds of constructors, default and copy constructors.
Default constructor:
- Can be called with no arguments
- Construct a default object of the class type.
Copy constructor:
- Can accept a single argument of reference to same class type
- Copy objects of the class type.
Constructors of base classes are not inherited by derived classes. When an object of derived class type is created, it is constructed starting with the base class components; then it moves to the derived class components.
Java supplies a hidden (or implicit) no-argument constructor by default, but only if the class has no explicitly defined constructors. So you can't count on the no-argument constructor always being available. Some programmers explicitly create one as a matter of habit, so they won't forget later, but this is not required.