1). Constructor:
A constructor in Java Programming is a block of code that initializes (constructs) the state and value during object creation.

Constructors are special methods in Java used to initialize objects when they are created. They are called automatically when you instantiate a class using the new keyword.

Prerequisites:
1. Should know about local and global variables
2. Global variables to non static variables
3. Default value of global variables
4. Return data types

Constructor behavior:
1). Constructor will be called automatically when objects are created
2). Constructor names should be a class names
3). Constructor will not have any return data types
4). Can be overloaded

2). Types of Constructors
A). Default Constructor
If no constructor is defined, Java provides a default one.
It has no parameters and initializes fields to default values (0, null, false).

B). No-Argument Constructor (User-Defined)
Explicitly written to initialize default values.

C). Parameterized Constructor
Takes arguments to initialize objects with specific values.

Example code for Types of Constructors:

public class SuperMarket {
    String product_name; 
    int price;
    int discount;

        // Parameterized Constructor
    public SuperMarket(String product_name, int price, int discount) {
        //Constructor
        this.product_name = product_name; 
        this.price    = price;  
        this.discount = discount;  
    }
        //Constructor Overloading
    public SuperMarket(String product_name, int price) {
        this.product_name = product_name; 
        this.price = price;  
    } 
        //Zero Argument Constructor / No-args Constructor
    public SuperMarket() { 
        System.out.println("Material from China");
    }

    public static void check() {
    //  System.out.println(this.product_name);
    }

    private void buy() {
        System.out.println(this.product_name + this.price);
    }

    public static void main(String[] args) {
        SuperMarket product1 = new SuperMarket("rice", 60,6); 
        SuperMarket product2 = new SuperMarket("Wheat", 50,5); 
        SuperMarket product3 = new SuperMarket("Coconut",25);

        SuperMarket product4 = new SuperMarket(); 

        System.out.println(product1.product_name);
        System.out.println(product2.product_name);
        product2.buy(); 
        //SuperMarket.check(); 
        check(); 
    }
}

Note: Static Fields(variables) and Methods can be called using Class_name or directly.

THIS Key word denotes current object.

--------------------------------- End of the Blog --------------------------------------------