What is meant by constructor?

Answer Posted / ravina gaikwad

Constructor is special type of member function that will
automatically invoke when an object creates. The purpose of
constructor is for the initialization of instance
variables. A constructor having the same name as that of
class name. It may have arguments but doesn't return
anything.
If we want to initialize all objects of the same class
with same values, use default constructor.Otherwise, we can
use parameterized constructor if we want to initialize
objects of the same class with different values. If we
don't specify any constructor , compiler will use default
constructor with garbage value.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between final, finally and finalize() in java?

527


How to reverse string in java?

623


When is the finalize() called? What is the purpose of finalization?

588


What is the difference between import java.util.date and java .util?

580


How can an object be unreferenced?

550






What does i ++ mean in Java?

509


Can a class be declared as static?

685


What is io stream in java?

529


What is off heap memory?

556


What is the purpose of the system class in java?

562


What do you understand by private, protected and public?

531


What is the impact of declaring a method as final?

567


What is the purpose of lambda expressions?

593


Differentiate between stringbuffer and string?

605


What is the exact difference in between unicast and multicast object? Where we will use?

566