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 |
What is an event?
Name four container classes.
Is a copy constructor?
What are mutable classes?
Difference between Interface & Abstract class?
what is difference between signed & unsigned char?
what is meta-Inf?
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?
What are Interceptors?
What does opcode mean?
what is inner class?