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

Write a program to reverse a number in java?

0 Answers  


Explain the Propertie sof class?

0 Answers  


Explain the differences between abstraction and encapsulation?

0 Answers  


What is the major difference between linkedlist and arraylist?

0 Answers  


Can we extend singleton class?

0 Answers  






What do you understand by the term string pool?

0 Answers  


Which characters are allowed to use as the second character of an identifier, and which characters are not allowed?

2 Answers  


What is the symbol for line break?

0 Answers  


Difference between a Scrollbar and a ScrollPane?

1 Answers  


Can you use abstract and final both with a method?

0 Answers  


What is passing by reference in java?

0 Answers  


Does java linked list allow duplicates?

0 Answers  


Categories