Difference between the Constructors and Methods

Last Updated : 16 Jun, 2026

In Java, constructors and methods are important components of a class that help in initializing objects and performing specific operations. A constructor is used to initialize an object when it is created, while a method defines the behavior and functionality of an object.

  • Both constructors and methods improve code reusability and program organization.
  • Java supports constructor and method overloading for multiple implementations.

Constructor

A constructor in Java is a special method used to initialize objects of a class. It is automatically called when an object is created and assigns initial values to object variables. Constructors help in setting up the initial state of an object.

  • Constructor has the same name as the class and does not have a return type.
  • It is automatically executed when an object is create

Syntax

class ClassName {
ClassName() {
// initialization code
}
}

Java
import java.io.*;

class Geek {
    int num;
    String name;

    // This would be invoked while an object
    // of that class created.
    Geek()
    {
        System.out.println("Constructor called");
    }
}

class GFG {
    public static void main(String[] args)
    {
        // this would invoke default constructor.
        Geek geek1 = new Geek();

        // Default constructor provides the default
        // values to the object like 0, null
        System.out.println(geek1.name);
        System.out.println(geek1.num);
    }
}

Output
Constructor called
null
0

Method

A method in Java is a block of code that performs a specific task or operation. Methods define the behavior of objects and help in improving code reusability. They execute only when they are called by the program.

  • Methods contain a return type, method name, and parameters.
  • They help in code reusability and modular programming.

Syntax

class ClassName {
returnType methodName(parameters) {
// method body
}
}

Java
import java.io.*;

class Addition {

    int sum = 0;

    public int addTwoInt(int a, int b)
    {

        // Adding two integer value.
        sum = a + b;

        // Returning summation of two values.
        return sum;
    }
}

class GFG {
    public static void main(String[] args)
    {

        // Creating an instance of Addition class
        Addition add = new Addition();

        // Calling addTwoInt() method
        // to add two integer
        // using instance created
        // in above step.
        int s = add.addTwoInt(1, 2);

        System.out.println("Sum of two "
                           + "integer values: "
                           + s);
    }
}

Output
Sum of two integer values: 3

Constructors Vs Methods

BasisConstructorMethod
PurposeUsed to initialize objects of a classUsed to perform specific operations or define object behavior
NameMust have the same name as the classCan have any valid name
Return TypeDoes not have any return typeMust have a return type or void
CallingAutomatically called when an object is createdCalled explicitly using the object name or class name
ExecutionExecutes only once when an object is createdCan be called multiple times whenever required
InheritanceCannot be inherited by subclassesCan be inherited by subclasses
OverloadingSupports constructor overloadingSupports method overloading and method overriding
Purpose of UseInitializes instance variables and sets object statePerforms calculations, operations, and other tasks
ModifiersCannot be static, final, or abstractCan use access modifiers like static, final, and abstract
SyntaxUses class name followed by parametersUses return type, method name, and parameters
Comment