What is meant by constructor?

Answers were Sorted based on User's Feedback



What is meant by constructor?..

Answer / 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

What is meant by constructor?..

Answer / dinesh

All the objects that are created must be given initial
values.There are two approach for this.
1)Using the dot operator to access the instance variables
and then assign values to them individually---This is a
tedious approach.
2)Use of getData method to initialize each object
individually.eg:add.getData(10,15)
To make this simpler Java supports a special type of method
called a Constructor,that enables an object to initialize
itself when it is created.Constructor have the same name as
the class itself and they do not specify a return type,not
even void,bcoz they return the instance of the class itself.

Is This Answer Correct ?    23 Yes 4 No

What is meant by constructor?..

Answer / onkdurga

constructor is a special type of member function,which has
the class name as function name.constructors doesn't have
any return type even void.constucter can be called
automatically at the time of object creation.Generally it
is used for initializing values to the data members.

constructorsare2types:1.default/parameterless
constructor
2.parametarized constructor

*costructor can not be inherited
*constructor can not be declared as static
*constructor can not be accessed outside of the class when
it is specified as private.

Is This Answer Correct ?    13 Yes 2 No

What is meant by constructor?..

Answer / ravikiran(aptech mumbai)

constructor is the one which is used to pass the
initializing parameters during instantiation

Is This Answer Correct ?    9 Yes 3 No

What is meant by constructor?..

Answer / ajay yadav

Constructor is defined as a type of member function which
calls itself when an object is created also has the same
name as of the class.

Is This Answer Correct ?    9 Yes 3 No

What is meant by constructor?..

Answer / suman blazta

Constructors are used to create and initialize objects of their class type.
Constructor is a special member function that takes the same name as the class name.The constructor is automatically named when an object is created. A constructor is named whenever an object is defined or dynamically allocated using the "new" operator.

Is This Answer Correct ?    4 Yes 0 No

What is meant by constructor?..

Answer / shiva

java allows objects to initilize themselves when they are
created .this automatic initilization is done wih the use
of constructor .a constructor is a special type of method
that has the same name of its class.when ever an object of
class is created,its constructor will be invoked and it
will initilized the object.the return type for a
constructor is not defined as it implicitly takes its class
type as return type.

Is This Answer Correct ?    5 Yes 5 No

What is meant by constructor?..

Answer / 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

More Core Java Interview Questions

Howmany classes that package java.applet.* contains?

1 Answers   TCS,


Is integer passed by reference in java?

0 Answers  


Where will it be used?

0 Answers  


What are user defined exceptions?

0 Answers  


what is the use of abstract class and interface with example?

2 Answers   Cycore, DNS, Technoram,






Does java list allow null?

0 Answers  


What is the use of volatile in java?

0 Answers  


Is arraylist ordered in java?

0 Answers  


Is arraylist sorted in java?

0 Answers  


Why deletion in linkedlist is fast than arraylist?

0 Answers  


What does exp mean in math?

0 Answers  


Explain the meaning of java applet.

0 Answers   TCS,


Categories