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

Explain about core java?

626


What is the difference between declaration and definition in java?

517


Can we catch more than one exception in a single catch block?

627


What is immutable data?

581


What is the reflection?

563






How do you test a method for an exception using junit?

533


Is string a wrapper class?

517


What are the Static and Dynamic Variables? Differentiate them.

605


how to open and edit XML file in Weblogic???

1551


What is super keyword explain with example?

533


What is exception propagation?

592


What are the benefits of immutable objects?

536


Can we assign integer value to char in java?

511


How can I right-justify a string?

627


Which is faster set or list in java?

530