Open links in new tab
    • Work Report
    • Email
    • Rewrite
    • Speech
    • Title Generator
    • Smart Reply
    • Poem
    • Essay
    • Joke
    • Instagram Post
    • X Post
    • Facebook Post
    • Story
    • Cover Letter
    • Resume
    • Job Description
    • Recommendation Letter
    • Resignation Letter
    • Invitation Letter
    • Greeting Message
    • Try more templates
  1. A constructor in Java is a special method used to initialize objects. It is automatically called when an instance of a class is created using the new keyword. A constructor must have the same name as the class and cannot have a return type, not even void.

    Key points:

    • Used to set initial values for object attributes.

    • Can be default, parameterized, copy, or private.

    • Supports overloading but cannot be overridden.

    Example – Default Constructor

    class Demo {
    Demo() {
    System.out.println("Default constructor called");
    }
    public static void main(String[] args) {
    Demo obj = new Demo(); // Calls default constructor
    }
    }
    Copied!

    If no constructor is defined, Java provides a default no-argument constructor that initializes fields with default values.

    Example – Parameterized Constructor

    class Person {
    String name;
    int age;
    Person(String name, int age) {
    this.name = name;
    this.age = age;
    }
    public static void main(String[] args) {
    Person p = new Person("Alice", 25);
    System.out.println(p.name + " - " + p.age);
    }
    }
    Copied!
    Feedback
  2. Java Constructors (With Examples) - Programiz

    Constructors in Java are similar to methods that are invoked when an object of the class is created. In this tutorial, we will learn about Java constructors and their types w…
    Example: Java Constructor

    Output: In the above example, we have created a constructor named Main(). Inside the constructor, we are initializing the value of the name variable. Notice the statement creating an object of the Mainclass. Here, when the object is created, the Main() con…

    Java no-arg Constructors

    Similar to methods, a Java constructor may or may not have any parameters (arguments). If a constructor does not accept any parameters, it is known as a no-argument constructor. For example,

    Java Parameterized Constructor

    A Java constructor can also accept one or more parameters. Such constructors are known as parameterized constructors (constructors with parameters).

    Java Default Constructor

    If we do not create any constructor, the Java compiler automatically creates a no-arg constructor during the execution of the program. This constructor is called the default constructor.

  3. Java Constructors - GeeksforGeeks

    Mar 26, 2026 · Explanation: Demonstrates constructor overloading by defining multiple Geeks constructors with different parameter lists. Based on the arguments passed while creating objects …

  4. Java Constructors - W3Schools

    Java Constructors A constructor in Java is a special method that is used to initialize objects. The constructor is called when an object of a class is created. It can be used to set initial values for object …

  5. How to Use Constructors in Java: A Beginner's Guide

    Jul 8, 2025 · Constructors are special types of methods with no return type. They are basically used to initialise the object, to set up its internal state, or to assign …

  6. Constructor in Java with Examples - First Code School

    Apr 3, 2024 · This article will discuss constructors in the Java programming …

    • boolean: false
    • long: 0L
    • char: \u0000
    • Type: Default Value
  7. Java - Constructors - Online Tutorials Library

    Java constructors are special types of methods that are used to initialize an object when it is created. It has the same name as its class and is syntactically similar …

  8. Constructors in Java – A Complete Guide - BeginnersBook

    May 30, 2024 · There are three types of constructors: Default, No-arg constructor and Parameterized. If you do not implement any constructor in your class, Java …

  9. Java Constructor - Class, Copy And Default Constructors

    Apr 1, 2025 · This tutorial will discuss Java Constructor, its types and concepts like constructor overloading and constructor chaining with code examples.

  10. Providing Constructors for Your Classes (The Javaâ„¢ Tutorials - Oracle

    This beginner Java tutorial describes fundamentals of programming in the Java programming language

  11. Java Constructor Examples: A Comprehensive Guide

    Jan 16, 2026 · This blog will provide a detailed overview of Java constructors, including fundamental concepts, usage methods, common practices, and best practices through various examples.

  12. People also ask
    Loading
    Unable to load answer