Constructor program in java => http://caibercasa.nnmcloud.ru/d?s=YToyOntzOjc6InJlZmVyZXIiO3M6MjE6Imh0dHA6Ly9iaXRiaW4uaXQyX2RsLyI7czozOiJrZXkiO3M6Mjc6IkNvbnN0cnVjdG9yIHByb2dyYW0gaW4gamF2YSI7fQ== There is no syntax for destructors in java. Whenever an object of the child class is created, the constructor of the parent class is invoked first. Example of parameterized constructor In this example, we have created the constructor of Student class that have two parameters. A default constructor is a constructor that either has no parameters, or if it has parameters, all the parameters have default values. If a class has three constructors, the first constructor can call the second one, which in turn calls the third one. Rules for creating Java constructor There are two rules defined for the constructor. We can have any number of parameters in the constructor. So in such situations, the compiler automatically writes one for you. Constructors Overloading in Java Similar like , you can also overload constructors if two or more constructors are different in parameters. Like methods, constructors can be overloaded. A static class is a class that has no objects, like a programming library I suppose would be. Java constructor chaining Constructor chaining occurs when a class inherits another class i. Sample Program - A method uses this to refer to the instance of the class that is executing the method. Prerequisite —In addition to overloading methods, we can also overload constructors in java. Overloaded constructor is called based upon the parameters specified when is executed. When do we need Constructor Overloading. Sometimes there is a need of initializing an object in different ways. This can be done using constructor overloading. For example, Thread class has 8 types of constructors. Consider the following implementation of a class Box with only one constructor taking three arguments. This means that all declarations of Box objects must pass three arguments to the Box constructor. Suppose we simply wanted a box object without initial dimension, or want to to initialize a cube by specifying only one value that would be used for all three dimensions. From the above implementation of Box class these options are not available to us. These types of problems of different ways of initializing an object can be solved by constructor overloading. Below is the improved version of class Box with constructor overloading. Please note, this should be the first statement inside a constructor. By using this statement inside it, the default constructor Box is implicitly called from it constructor program in java will initialize dimension of Box with -1. Note : The constructor calling should be first statement in the constructor body. For example, following fragment is invalid and throws compile time error. Constructors overloading vs Method overloading Strictly speaking, constructor overloading is somewhat similar to method overloading. If we want to have different ways of initializing an object using constructor program in java number of parameters, then we must do constructor overloading as we do method overloading when we want different definitions of a method based on different parameters. This article is contributed by Gaurav Miglani. If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to contribute geeksforgeeks. See your article appearing on the GeeksforGeeks main page and help other Geeks. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.