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 |
List some java keywords sun like c, c + + keywords?
how to write a program for chat function using core java
what is multithreading?
Is it necessary that each try block must be followed by a catch block?
What are the procedures?
Can an unreachable object become reachable again?
what is mutual exclusion? How can you take care of mutual exclusion using java threads? : Java thread
What is difference between Iterator and for loop
What is meant by class loader? How many types are there? When will we use them?
What is Recursion Function?
What is the meaning of variable in research?
Is void a data type?