What is the difference between method and constructor ?
Answer Posted / dineshkumar
A method is a set of code that will perform a specific task. It must have a name which is accurate to the task it performs, must have a return type(if nothing must be prefixed with void), an optional access specifier, may have parameters/arguments. It is called whenever it is needed.A method can be overloaded and overridden.
A constructor is a special block of code which has the same name as its class name with no return type. It is executed only once for an instance of the class. It is, logically, used for initializing the object(its parameters). A constructor cannot be overridden but can be overloaded by differing no.of arguments.
Is This Answer Correct ? | 12 Yes | 3 No |
Post New Answer View All Answers
Explain the concept of hashtables?
What is a variable declaration?
What is the use of math abs in java?
What is outofmemoryerror in java?
Explain jvm, jre, and jdk?
What does || mean in vectors?
Why runnable interface is used in java?
What are the two ways in which thread can be created?
Is upper case in java?
What is return code?
How do you sort a string in java?
What is the console in java?
What is constant in programming?
Is java written in c?
Explain when classnotfoundexception will be raised ?