Can you elaborate a little more on the question? All object creation is done through constructors. If no constructor is specified, the compiler will supply a default empty constructor that basically does nothing. If you wish to provide info that initializes some values in the object when it's created, you provide a constructor for those parameters and initialize those values in that constructor.
1. Constructor is use to create instance of a class. In case, you want to initialize your object at the time of creation, you have to define constructor. If you don't define any constructor, the default constructor defined by Object class is used to create the instance. Hence, without constructor, you can't create any object in java.
2. What do you mean by we can initialize directlt. I guess you want to say that we can set value directly. Initialize means setting the value at the time of object creation.
We use/call constructors to create instances of objects. In that way we can call the methods of the class.
We define different constructors for different functionality based on their arguments.
WHAT IS CONSTRUCTOR
1. A constructor creates an Object of the class and by initializing all the instance variables and creating a place in memory to hold the Object.
2. It is called using "new "
Why we Need Constructor
1. For simple programs , initializing can be done by user. that will not be a prob.
But consider a case where there is 20 or more instance member.
If the programmer make the user to initialize all , that will be very bad way of programming.
Actually we use constructor in java to have initialization done by the program it self when the time of objected is created.so when the object is initialized the the respected method will be alled or executed.
i am using visual studio 2015 and trying to export data which i am importing through excel by the user selected Excel file. Now the importing part has been successfully completed i am using OLEDB Connection but Stuck in exporting the same data to a new Excel file. tried ...
I am creating a program that when you print an author, you must show all the information of all the books that the author has written. Add a new attribute in the Author class that will be "BooksWriting: List (Book)".
I am currently creating a simulation of a pizza ordering system in object oriented program. I have some question. the instruction and guideline is long but I will try and cut it down a lot. the instruction is to create a program that simulate a pizza restaurant using ...