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

What do you mean by formatting?

0 Answers  


What does singleton class mean?

0 Answers  


How will you print number in reverse (descending) order in BST.

0 Answers   GrapeCity,


What is the difference between a break statement and a continue statement?

0 Answers  


What's the purpose of using break in each case of switch statement?

0 Answers  






Does .length start 0 java?

0 Answers  


explain local datetime api in java8?

0 Answers  


Why collection doesn’t extend cloneable and serializable interfaces?

0 Answers  


How to convert string to int in java?

1 Answers  


What is the current version of java?

0 Answers  


What invokes a thread's run() method in java programming?

0 Answers  


What is a stack class in java ?

0 Answers   Akamai Technologies,


Categories