waht happens when a return type ,even void is specified for
a constructor?
Answers were Sorted based on User's Feedback
The constructor has the same name as that of the class to
which it belongs to. When a return type or void is
specified,no error occurs.It will be considered as a method.
for example:
public class myclass
{
public myclass()
...
}this is considered as a contrustor
whereas,
public class myclass
{
public void myclass()
{
...
}will be considered as a method.....
Is This Answer Correct ? | 33 Yes | 3 No |
Answer / ramanareddy333
simply it will considered as a normal method in the class
Is This Answer Correct ? | 19 Yes | 1 No |
Answer / rajesh
Nothing to be happen
the program might compile the output wont come.
Is This Answer Correct ? | 9 Yes | 3 No |
Answer / krishna kumar g.
Answer 2 is exactly correcr.I have done practiclly.No
compile time errors.
Code will run and executes sucessfully.But it treats as
method not as constructor.
Is This Answer Correct ? | 5 Yes | 1 No |
Answer / sasikumar m
If return type is mentioned, then that will become a normal
method. Otherwise that will be considered as a constructor.
Is This Answer Correct ? | 6 Yes | 2 No |
Answer / amir
answer 3 is 100% right... it will compile time error
constructor cannot have return type specification
Is This Answer Correct ? | 2 Yes | 0 No |
Answer / shankar
*A constructor is a special method which has the same name
as that of the class which is used for the initialising and
instance,when it is being created itself.
*Normal method may or may not returns values when a normal
method does not return value it is mentioned explicitly
with void keyword
**ANSWER**-- 7 is write
Is This Answer Correct ? | 1 Yes | 1 No |
Answer / susheel s
Answer 3 is absolutely right becuse compiler strictly
follows the syntax. Except answer 3 all are wrong.
Is This Answer Correct ? | 2 Yes | 8 No |
What is the difference between hashset and treeset in java?
What is a predicate method?
"we cannot create an object of interface but we can create a variable of it".diacuss the statement with the help of an example.
Is empty list java?
What is the use of volatile in java?
What is the constructor?
Difference between object instantiation and construction ?
How we can make copy of a java object?
static inner classes means..?
how is final different from finally and finalize in java?
Can we catch more than one exception in single catch block?
What is the difference between variable & constant?