Difference between constructor and method in Java

Java Programming Object Oriented ProgrammingJava8

Following are the difference between constructor and method.

  • Constructor is used to initialize an object whereas method is used to exhibits functionality of an object.

  • Constructors are invoked implicitly whereas methods are invoked explicitly.

  • Constructor does not return any value where the method may/may not return a value.

  • In case constructor is not present, a default constructor is provided by java compiler. In the case of a method, no default method is provided.

  • Constructor should be of the same name as that of class. Method name should not be of the same name as that of class.

Published on 22-Apr-2018 20:06:51