What is meant by constructor?

Answer Posted / bindhu

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 ?    35 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How will you get the platform dependent values like line separator, path separator, etc., ?

559


Explain a situation where finally block will not be executed?

556


What is the collections api?

550


Do you know why doesn't the java library use a randomized version of quicksort?

523


What is ide with example?

522






What are the application of stack?

477


What is difference between filereader and bufferedreader?

506


What are the differences between stringbuffer and stringbuilder?

521


What is variable argument in java?

534


Explain about data types?

547


Explain about the main() method in java?

544


Can you create an object of an abstract class?

527


What are the two ways of implementing multi-threading in java?

787


What methods are used to get and set the text label displayed by a button object?

527


Which variables are stored in heap?

520