why constructor dont have returns type?
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
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 |
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 |
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 |
Answer / nn
As far as I know, constructor returns the new object.
Is This Answer Correct ? | 2 Yes | 24 No |
Write a program to reverse a number in java?
Explain the Propertie sof class?
Explain the differences between abstraction and encapsulation?
What is the major difference between linkedlist and arraylist?
Can we extend singleton class?
What do you understand by the term string pool?
Which characters are allowed to use as the second character of an identifier, and which characters are not allowed?
What is the symbol for line break?
Difference between a Scrollbar and a ScrollPane?
Can you use abstract and final both with a method?
What is passing by reference in java?
Does java linked list allow duplicates?