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:-
- Constructor is used to initialize the object or instance of class whereas a method is used to perform specific task or functionality.
- 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.
- Constructor must have no return type (Not even void) in declaration whereas a method should have a return type (Including void) in declaration.
- A constructor can be called explicitly (Parameterized constructor) or implicitly ( No arg constructor) whereas a method needs to be called explicitly always.
- 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.
- Constructors are not inherited while non-static methods are inherited.
- Constructors cannot be overridden whereas methods can be overridden.
- 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 ).
- A constructor can call another constructor using this() or super() whereas a method can call other method directly or using class or object reference.
- A constructor cannot be static, abstract , final, native or synchronized whereas a method can be.
- A constructor can bring method (Non-static) in existence/memory.