Let’s start with very basic definitions of both Constructor and Methods in Java:-

A constructor of a class is used to initialize the object or instance of class using new keyword. It can be called as special method as it is different from normal methods. It differs from methods as a constructor should have same name as class name and should not have any return type.

A method is a set of code with name to perform specific actions whenever and wherever needed. A method can accept parameters and return value.

Now see the differences between Constructor and Method:-

  1. Constructor is used to initialize the object or instance of class whereas a method is used to perform specific task or functionality.
  2. Constructor must have same name as class name whereas a method can have any valid name. A method can have name same as class name with a return type.
  3. Constructor must have no return type (Not even void) in declaration whereas a method should have a return type (Including void) in declaration.
  4. A constructor can be called explicitly (Parameterized constructor) or implicitly ( No arg constructor) whereas a method needs to be called explicitly always.
  5. If a class does not have any constructor, a default constructor is provided. There is no default method concept. You need to create it explicitly.
  6. Constructors are not inherited while non-static methods are inherited.
  7. Constructors cannot be overridden whereas methods can be overridden.
  8. A constructor can be called using new keyword whereas method can be called using object (Non static methods ) or class reference ( Static methods) or by name ( Calling Non static method in another non static method and Calling static method in another static method ).
  9. A constructor can call another constructor using this() or super() whereas a method can call other method directly or using class or object reference.
  10. A constructor cannot be static, abstract , final, native or synchronized whereas a method can be.
  11. A constructor can bring method (Non-static) in existence/memory.

#ThanksForReading

Author: Amod Mahajan

My name is Amod Mahajan and I am an IT employee with 6+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went through so many selenium tutorials. Thanks to Mukesh Otwani as his tutorials are easy and cover basics to advance. I have habit of exploring concepts by deep diving. I used to make notes. I thought of sharing my knowledge through posts and now I am here. #KeepLearning #ShareLearning

2 thoughts on “Difference Between Constructor and Method in Java

Leave a Reply