Difference between the Constructors and Methods Last Updated : 05 Sep, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report Java is a pure OOPS concept based programming language. Hence in Java, all the variables, data and the statements must be present in classes. These classes consist of both constructors and methods. Methods and Constructors are different from each other in a lot of ways. Constructors: Constructors are used to initialize the object's state. Like methods, a constructor also contains collection of statements(i.e. instructions) that are executed at time of Object creation. Each time an object is created using new() keyword at least one constructor (it could be default constructor) is invoked to assign initial values to the data members of the same class. Example: Java // Java Program to illustrate constructor 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 Methods: A method is a collection of statements that perform some specific task and return the result to the caller. A method can perform some specific task without returning anything. Methods allow us to reuse the code without retyping the code. In Java, every method must be part of some class which is different from languages like C, C++, and Python. Example: Java // Java Program to illustrate methods 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 Differences between Constructors and Methods: ConstructorsMethodsA Constructor is a block of code that initializes a newly created object.A Method is a collection of statements which returns a value upon its execution.A Constructor can be used to initialize an object.A Method consists of Java code to be executed.A Constructor is invoked implicitly by the system.A Method is invoked by the programmer.A Constructor is invoked when a object is created using the keyword new.A Method is invoked through method calls.A Constructor doesn't have a return type.A Method must have a return type.A Constructor initializes a object that doesn't exist.A Method does operations on an already created object.A Constructor's name must be same as the name of the class.A Method's name can be anything.A class can have many Constructors but must not have the same parameters.A class can have many methods but must not have the same parameters.A Constructor cannot be inherited by subclasses.A Method can be inherited by subclasses. Comment More infoAdvertise with us Next Article Difference between the Constructors and Methods D DannanaManoj Follow Improve Article Tags : Misc Java Difference Between Java-Object Oriented Java-Constructors Java-Functions +2 More Practice Tags : JavaMisc Similar Reads Java Tutorial Java is a high-level, object-oriented programming language used to build web apps, mobile applications, and enterprise software systems. It is known for its Write Once, Run Anywhere capability, which means code written in Java can run on any device that supports the Java Virtual Machine (JVM).Java s 10 min read Java OOP(Object Oriented Programming) Concepts Java Object-Oriented Programming (OOPs) is a fundamental concept in Java that every developer must understand. It allows developers to structure code using classes and objects, making it more modular, reusable, and scalable.The core idea of OOPs is to bind data and the functions that operate on it, 13 min read Java Interview Questions and Answers Java is one of the most popular programming languages in the world, known for its versatility, portability, and wide range of applications. Java is the most used language in top companies such as Uber, Airbnb, Google, Netflix, Instagram, Spotify, Amazon, and many more because of its features and per 15+ min read Non-linear Components In electrical circuits, Non-linear Components are electronic devices that need an external power source to operate actively. Non-Linear Components are those that are changed with respect to the voltage and current. Elements that do not follow ohm's law are called Non-linear Components. Non-linear Co 11 min read SQL Commands | DDL, DQL, DML, DCL and TCL Commands SQL commands are crucial for managing databases effectively. These commands are divided into categories such as Data Definition Language (DDL), Data Manipulation Language (DML), Data Control Language (DCL), Data Query Language (DQL), and Transaction Control Language (TCL). In this article, we will e 7 min read Arrays in Java Arrays in Java are one of the most fundamental data structures that allow us to store multiple values of the same type in a single variable. They are useful for storing and managing collections of data. Arrays in Java are objects, which makes them work differently from arrays in C/C++ in terms of me 15+ min read TCP/IP Model The TCP/IP model is a framework that is used to model the communication in a network. It is mainly a collection of network protocols and organization of these protocols in different layers for modeling the network.It has four layers, Application, Transport, Network/Internet and Network Access.While 7 min read Collections in Java Any group of individual objects that are represented as a single unit is known as a Java Collection of Objects. In Java, a separate framework named the "Collection Framework" has been defined in JDK 1.2 which holds all the Java Collection Classes and Interface in it. In Java, the Collection interfac 15+ min read Inheritance in Java Java Inheritance is a fundamental concept in OOP(Object-Oriented Programming). It is the mechanism in Java by which one class is allowed to inherit the features(fields and methods) of another class. In Java, Inheritance means creating new classes based on existing ones. A class that inherits from an 13 min read Spring Boot Tutorial Spring Boot is a Java framework that makes it easier to create and run Java applications. It simplifies the configuration and setup process, allowing developers to focus more on writing code for their applications. This Spring Boot Tutorial is a comprehensive guide that covers both basic and advance 10 min read Like