why constructor dont have returns type?

Answers were Sorted based on User's Feedback



why constructor dont have returns type?..

Answer / venkatesh

Constructor donot return any data.it is mainly used for
initialization i.e one time activity like database
connectiviy, constructors are automatically invoked when
created objects created.

Is This Answer Correct ?    32 Yes 2 No

why constructor dont have returns type?..

Answer / krushna

because the constructor is not method

Is This Answer Correct ?    3 Yes 1 No

why constructor dont have returns type?..

Answer / subrat

This is what differenciates constructor from a method. If
constructor have a return type then the JVM will not treat
constructor as constructor but as method.

Is This Answer Correct ?    5 Yes 4 No

why constructor dont have returns type?..

Answer / vishwanath

because it is called implicitly when object is created... so it doesn't have any target to return values....
for ex..
int v=Integer.parseInt(X.readLine());
int n=fact(v);
int fact(int)
{
.....return ans
}
so it return ans to the variable n which is assigned to calling statement..... when compared the constructor don't have any target to return

Is This Answer Correct ?    0 Yes 0 No

why constructor dont have returns type?..

Answer / sushila

constructor does not have a return type. it is not executed,
while loading class into the memory.

constructor is executed only once for each object.

Is This Answer Correct ?    0 Yes 0 No

why constructor dont have returns type?..

Answer / mahesh

we need not to call a constructor so it need not to return
any value for us thats y it does not contain a return type.....

Is This Answer Correct ?    1 Yes 2 No

why constructor dont have returns type?..

Answer / praveen mooli

The value is this object itself so there is no need to
indicate a return value.

Is This Answer Correct ?    2 Yes 4 No

why constructor dont have returns type?..

Answer / sankar r k

The function of the constructor is to assign values to the
instance variable when the object is created for the first
time.The name of the constructor and the class name will be
same.

Is This Answer Correct ?    0 Yes 2 No

why constructor dont have returns type?..

Answer / nn

As far as I know, constructor returns the new object.

Is This Answer Correct ?    2 Yes 24 No

Post New Answer

More Core Java Interview Questions

What is an event?

2 Answers  


Name four container classes.

0 Answers  


Is a copy constructor?

0 Answers  


What are mutable classes?

0 Answers  


Difference between Interface & Abstract class?

5 Answers  






what is difference between signed & unsigned char?

2 Answers  


what is meta-Inf?

2 Answers   Polaris,


What is the difference between pageContext and page implicit objects in jsp?

9 Answers   Gspann Technologies, Merrill Lynch, Polaris,


What is file class and what is its purpose?

1 Answers  


What are Interceptors?

1 Answers  


What does opcode mean?

0 Answers  


what is inner class?

6 Answers   HCL,


Categories