Monday, 8 December 2014

What is the difference between constructor and method



             Constructor:                                                                     Method:

1) Constructor is used to initialize the state of   1) Method is used to expose the  behaviour
   of  an object.                                                       of an object                                                              
2) Constructor must not have return type.           2) Method must have return type.
3)Constructor is invoked implicitly                     3) Method is invoked explicitly
  (automatically).                                                          (we have to call)
4) The java compiler provides a default              4) Method is not provided by compiler in                  constructor if you don't have any constructor.                  any case.        
5) Constructor name must be same as the class   5) Method name may or may not be same
      class name.                                                             as class name.
                    

No comments:

Post a Comment