Check out example codes for "java constructor". It will help you in understanding the concepts better.

Code Example 1

// Create a MyClass class
public class MyClass {
  int x;  // Create a class attribute

  // Create a class constructor for the MyClass class
  public MyClass() {
    x = 5;  // Set the initial value for the class attribute x
  }

  public static void main(String[] args) {
    MyClass myObj = new MyClass(); // Create an object of class MyClass (This will call the constructor)
    System.out.println(myObj.x); // Print the value of x
  }
}

// Outputs 5

Code Example 2

class Other{
    public Other(String message){
        System.out.println(message);
    }
}

class scratch{
    public static void main(String[] args) {
        Other method = new Other("Hey");
        //prints Hey to the console
    }
}

Code Example 3

Code that runs whenever an object is made 

example:

class bruh{
    
    bruh(){
        //code 
    }
};

int main()
{
    bruh bruhobject(); 
//can take parameters, code runs whenever object is created

}

Code Example 4

class MyClass {
  public MyClass () {
    //constructor code
  }
}

Learn ReactJs, React Native from akashmittal.com