Methods Vs Constructors in Java
What is the difference between Methods and Constructors in Java?
No. |
Methods |
Constructors |
1
|
It is not necessary to use the same name of the class to create a Method.
|
The name of the Constructor should be same as the class name it
resides.
|
2
|
Method is an ordinary member function which is used to expose the behavior of an object
|
Constructor is a member function of a class used to initialize the
state of an object
|
3
|
Methods must have return type unless it is specified as void.
|
Constructor does not have a return type.
|
4
|
Compiler does not create a method in any case if one is not
available.
|
Java compiler creates default constructor if the program doesn’t have
one.
|
5
|
Methods invoked explicitly.
Invoked using the dot operator.
|
Constructor invoked implicitly. i. e. Invoked using the keyword ‘new’.
|