Answer: A constructor creates an Object of the class that it is in by initializing all the instance variables and creating a place in memory to hold the Object. It is always used with the keyword new and then the Class name. For instance, new String(); constructs a new String object.
COnstructors are basically used to initialize the attributes of the class.
Question:
What do u mean contructor in java ? Answer:
A constructor creates an Object of the class that it is in by initializing all the instance variables and creating a place in memory to hold the Object. It is always used with the keyword new and then the Class name. For instance, new String(); constructs a new String object.
COnstructors are basically used to initialize the attributes of the class. Source: CoolInterview.com
Constructor in java:
Constructor is just method in a class with pre defined characteristics. Below are some of these
1. Constructor name should be same as class name 2. Constructor should not return any value. 3. Constructor will be the first method (other than static block of code) that will be invoked while creating the class instance.
Generally we will use the constructor for initialising the services that will be used in class. Source: CoolInterview.com
Constuctor is a definition block used to create the initial state of an object with the desired value. The constuctor should have the same name as that of the class. Source: CoolInterview.com