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

What does \ mean in regex?

836


What is the difference between the jdk 1.02 event model and the event-delegation model introduced with jdk 1.1?

848


What initialize variables?

695


What will be the initial value of an object reference which is defined as an instance variable?

892


Why java is platform independent? Explain.

778


What is difference between iterator access and index access?

841


Why can't we use static class instead of singleton?

702


Describe how to implement singleton design pattern in struts.

764


What is a java applet? What is an interface?

848


Write a program to reverse a number in java?

783


What do you understand by garbage collection in Java? Can it be forced to run?

751


Which is bigger double or float?

718


Why java is a platform independent? Explain

748


What is concurrent hashmap and its features?

750


Which methods cannot be overridden in java?

740