Please I really need to know what is a constructor? How do you differentiate between a constructor and a default constructor? Can someone please explain in detail, because I can't seem to find any info on the web. Thank you.
Please I really need to know what is a constructor? How do you differentiate between a constructor and a default constructor? Can someone please explain in detail, because I can't seem to find any info on the web. Thank you.
Normally, constructor in java is a special method that is used to initialize a newly created object and is called just after the memory is allocated for the object. It can be used to initialize the objects ,to required ,or default values at the time of object creation.
Constructor is similar to a function which u have declared in the class except it does not have return type and it cannot be static in java. Constructor is used to initialize an object becoz
* Constructor is automatically invoked when ever object is created..
* Calling constructor will initialize a default values to a non static member variables in the class..
Default constructor is one type of constructor which does not have parameters(arguments)..
EG:
class first
{
// Default Constructor
first()
{
}
}
Constructors are used to initiate the object parameter. Some default values will be given to the parameters whenever that class is called. So it is very important to use deconstructor, every time you make use of Constructors .
Normally the constructor is the block of statements, that get executes as soon as the instance of class is created. it normally used for initializing the variables.
Some of the useful property of constructor are as follow:
- The constructor can be non-parametrized (//Also known as default constructor) and parametrized constructor.
- The constructor don't have any return type.
- The Class name and the constructor name should always be same.
- We can also execute the super class constructor with the help of super keywords.
- The constructor can't be execute with the help of object.
Bookmarks