{"id":2236,"date":"2020-03-19T16:50:50","date_gmt":"2020-03-19T16:50:50","guid":{"rendered":"https:\/\/www.h2kinfosys.com\/blog\/?p=2236"},"modified":"2020-04-07T18:20:25","modified_gmt":"2020-04-07T12:50:25","slug":"what-are-constructors-and-overloading","status":"publish","type":"post","link":"https:\/\/www.h2kinfosys.com\/blog\/what-are-constructors-and-overloading\/","title":{"rendered":"What are Constructors and Overloading"},"content":{"rendered":"<h2><b>Constructor<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">is a special method that has no return type and matches the name of the class. They are using for the creation of new objects. For example:\u00a0<\/span><\/p>\n<p style=\"padding-left: 60px;\"><i><span style=\"font-weight: 400;\">public class Fish {<br \/>\n<\/span><\/i><i><span style=\"font-weight: 400;\">public Fish() {<br \/>\n<\/span><\/i><i><span style=\"font-weight: 400;\">System.out.println(&#8220;constructor&#8221;);<br \/>\n<\/span><\/i><i><span style=\"font-weight: 400;\">}<br \/>\n<\/span><\/i><i><span style=\"font-weight: 400;\">}<\/span><\/i><span style=\"font-weight: 400;\">\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The creation of new object is called instantiation, because it creates a new instance of the class. To call constructor we need to write keyword <\/span><i><span style=\"font-weight: 400;\">new<\/span><\/i><span style=\"font-weight: 400;\"> followed by the name of the class we want to instantiate: new <\/span><i><span style=\"font-weight: 400;\">Fish<\/span><\/i><span style=\"font-weight: 400;\">().<\/span><\/p>\n<p><span style=\"font-weight: 400;\">There are three types of constructors in the<a href=\"https:\/\/www.h2kinfosys.com\/courses\/java-online-training-course-details\"> Java language<\/a>:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">default constructors;<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">constructors without arguments;<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">parameterized constructors.<\/span><\/li>\n<\/ul>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"wp-image-2237 aligncenter\" src=\"https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/03\/Screenshot_53.png\" alt=\"\" width=\"713\" height=\"320\" title=\"\" srcset=\"https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/03\/Screenshot_53.png 795w, https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/03\/Screenshot_53-300x135.png 300w, https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/03\/Screenshot_53-768x345.png 768w\" sizes=\"(max-width: 713px) 100vw, 713px\" \/><\/p>\n<h2><b>Default constructors.<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Every class in <a href=\"https:\/\/www.h2kinfosys.com\/blog\/what-is-java\/\">Java<\/a> has a constructor. If you don\u2019t create any constructors in the class, Java will add one for you without any parameters. It is called the <\/span><b>default constructor<\/b><span style=\"font-weight: 400;\">. Let&#8217;s create a class without any constructor:<\/span><\/p>\n<p style=\"padding-left: 60px;\"><i><span style=\"font-weight: 400;\">public class Dog {\u00a0\u00a0<\/span><\/i><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"font-weight: 400;\">}\u00a0<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">Java compiler will generate the constructor for us:<\/span><\/p>\n<p style=\"padding-left: 60px;\"><i><span style=\"font-weight: 400;\">public Dog() {}<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400;\">This will happen during compilation. If you check at the file <\/span><b>Dog.java<\/b><span style=\"font-weight: 400;\">, the constructor will still be missing. It is only in the compiled file Dog.class that it makes an appearance. It is important to remember that a default constructor is only supplied if there are no constructors present. It does not have any arguments. Most of the time it is fine to have just default constructor because other fields can be accessed and initialized through getters and setters methods.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><b>Constructors without arguments. <\/b><span style=\"font-weight: 400;\">Sometimes the default constructor is not enough. In this case, we can create a constructor with the same signature as default, but with a body. It will be some kind of overriding the default method. We don&#8217;t pass any argument to this constructor to initialize class fields, but we can do some logging, checking network connection, checking resources, etc. Let&#8217;s look at the example:<\/span><\/p>\n<p style=\"padding-left: 60px;\"><i><span style=\"font-weight: 400;\">public class Monkey {<br \/>\n<\/span><\/i><i><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 public Monkey() {<br \/>\n<\/span><\/i><i><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 System.out.println(\u201cObject of the class Monkey is created\u201d);<br \/>\n<\/span><\/i><i><span style=\"font-weight: 400;\">}<br \/>\n<\/span><\/i><i><span style=\"font-weight: 400;\">public static void main (String[] args) {<br \/>\n<\/span><\/i><i><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0Monkey myMonkey = new Monkey();<br \/>\n<\/span><\/i><i><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0}<br \/>\n<\/span><\/i><i><span style=\"font-weight: 400;\">}<\/span><\/i><\/p>\n<p><b>Parameterized constructors.<\/b> Constructors are typically used to initialize <a href=\"https:\/\/www.h2kinfosys.com\/blog\/java-variables-and-data-types\/\">instance variables<\/a>. For example:<\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; line-height: 1; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public class Fish {\u00a0<\/span><\/p>\n<p dir=\"ltr\" style=\"text-indent: 17.25pt; margin-top: 0pt; margin-bottom: 0pt; line-height: 1; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">private int weight;\u00a0<\/span><\/p>\n<p dir=\"ltr\" style=\"text-indent: 17.25pt; margin-top: 0pt; margin-bottom: 0pt; line-height: 1; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">private int length;<\/span><\/p>\n<p dir=\"ltr\" style=\"text-indent: 17.25pt; margin-top: 0pt; margin-bottom: 0pt; line-height: 1; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public Fish(int weight, int length) {\u00a0<\/span><\/p>\n<p dir=\"ltr\" style=\"text-indent: 37.5pt; margin-top: 0pt; margin-bottom: 0pt; line-height: 1; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">this.weight = weight;\u00a0<\/span><\/p>\n<p dir=\"ltr\" style=\"text-indent: 37.5pt; margin-top: 0pt; margin-bottom: 0pt; line-height: 1; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">this.length = \u00a0length;<\/span><\/p>\n<p dir=\"ltr\" style=\"text-indent: 17.25pt; margin-top: 0pt; margin-bottom: 0pt; line-height: 1; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p dir=\"ltr\" style=\"text-indent: 17.25pt; margin-top: 0pt; margin-bottom: 0pt; line-height: 1; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public printInfo() {<\/span><\/p>\n<p dir=\"ltr\" style=\"text-indent: 17.25pt; margin-top: 0pt; margin-bottom: 0pt; line-height: 1; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">System.out.println(\u201cThe fish weight is \u201d + weight + \u201c and length is \u201d + length);<\/span><\/p>\n<p dir=\"ltr\" style=\"text-indent: 17.25pt; margin-top: 0pt; margin-bottom: 0pt; line-height: 1; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p dir=\"ltr\" style=\"text-indent: 17.25pt; margin-top: 0pt; margin-bottom: 0pt; line-height: 1; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public static void main (String[] args) {<\/span><\/p>\n<p dir=\"ltr\" style=\"text-indent: 17.25pt; margin-top: 0pt; margin-bottom: 0pt; line-height: 1; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\/\/ creation of our objects with specific field values<\/span><\/p>\n<p dir=\"ltr\" style=\"text-indent: 17.25pt; margin-top: 0pt; margin-bottom: 0pt; line-height: 1; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">Fish myFish1 = new Fish (290, 30);<\/span><\/p>\n<p dir=\"ltr\" style=\"text-indent: 17.25pt; margin-top: 0pt; margin-bottom: 0pt; line-height: 1; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">Fish myFish2 = new Fish (120, 17);<\/span><\/p>\n<p dir=\"ltr\" style=\"text-indent: 17.25pt; margin-top: 0pt; margin-bottom: 0pt; line-height: 1; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\/\/calling methods to display values of our objects<\/span><\/p>\n<p dir=\"ltr\" style=\"text-indent: 17.25pt; margin-top: 0pt; margin-bottom: 0pt; line-height: 1; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">myFish1.printInfo();<\/span><\/p>\n<p dir=\"ltr\" style=\"text-indent: 17.25pt; margin-top: 0pt; margin-bottom: 0pt; line-height: 1; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">myFish2.printInfo();<\/span><\/p>\n<p dir=\"ltr\" style=\"text-indent: 17.25pt; margin-top: 0pt; margin-bottom: 0pt; line-height: 1; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p dir=\"ltr\" style=\"margin-top: 0pt; margin-bottom: 0pt; line-height: 1; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">} <\/span><\/p>\n<p><span style=\"font-weight: 400;\">Here we assign the parameters <\/span><i><span style=\"font-weight: 400;\">weight<\/span><\/i><span style=\"font-weight: 400;\"> and <\/span><i><span style=\"font-weight: 400;\">length <\/span><\/i><span style=\"font-weight: 400;\">to the instance variable <\/span><i><span style=\"font-weight: 400;\">weight <\/span><\/i><span style=\"font-weight: 400;\">and<\/span><i><span style=\"font-weight: 400;\"> length<\/span><\/i><span style=\"font-weight: 400;\">. Keyword <\/span><i><span style=\"font-weight: 400;\">this<\/span><\/i><span style=\"font-weight: 400;\"> tells Java that you want to reference an instance variable. In the method <\/span><i><span style=\"font-weight: 400;\">main <\/span><\/i><span style=\"font-weight: 400;\">we are creating two objects of the class <\/span><i><span style=\"font-weight: 400;\">Fish <\/span><\/i><span style=\"font-weight: 400;\">with a different value of fields <\/span><i><span style=\"font-weight: 400;\">weight <\/span><\/i><span style=\"font-weight: 400;\">and<\/span><i><span style=\"font-weight: 400;\"> length<\/span><\/i><span style=\"font-weight: 400;\">. The output of the current code will be:<\/span><\/p>\n<p style=\"padding-left: 60px;\"><i><span style=\"font-weight: 400;\">The fish weight is 290 and length is 30<br \/>\n<\/span><\/i><i><span style=\"font-weight: 400;\">The fish weight is 120 and length is 17<\/span><\/i><\/p>\n<p><b>Overloading of constructors in Java<\/b><\/p>\n<p><span style=\"font-weight: 400;\">In Java, we can overload all methods, including constructors. Your class can have multiple constructors in the same class, but with a different signature. The name of constructors is always the same since it has to be the same as the name of the class. So constructors must have different parameters in the list and their types in order to be overloaded.<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public class Mouse() {<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">private int weight;\u00a0<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">private String color;\u00a0<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public Mouse(int weight) {<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">this.weight = weight;<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public Mouse(int weight, String color) {<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">this.weight = weight;<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">this.color = color;<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public static void main (String[] args) {<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0Mouse myMouse = new Mouse(350);<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">Mouse myGrayMouse = new Mouse(350, \u201cgray);<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">} <\/span><\/p>\n<p dir=\"ltr\"><span style=\"font-weight: 400;\">Overloaded constructors can call each other. This approach is called <\/span><b>constructor chaining<\/b><span style=\"font-weight: 400;\">. For example:<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public class Mouse() {<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">private int weight;\u00a0<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">private String color;\u00a0<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">private String name;<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public Mouse(int weight) {<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">this.weight = weight;<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">System.out.println(\u201cWe are in the constructor with signature Mouse(int weight).\u201d);<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public Mouse(int weight, String color) {<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">this(weight);<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">this.color = color;<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">this.name = name;<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">System.out.println(\u201cWe are in the constructor with signature Mouse(int weight, String color).\u201d);<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public Mouse(int weight, String color, String name) {<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">this(weight, color);<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">this.name = name;<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">System.out.println(\u201cWe are in the constructor with signature Mouse(int weight, String color, String name).\u201d);<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public static void main (String[] args) {<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0Mouse myMouse = new Mouse(350, \u201cgray\u201d, \u201cMickey\u201d);<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">} <\/span><\/p>\n<p><span style=\"font-weight: 400;\">The output of the current application will be:<\/span><\/p>\n<p><i><span style=\"font-weight: 400;\">We are in the constructor with signature Mouse(int weight).<br \/>\n<\/span><\/i><i><span style=\"font-weight: 400;\">We are in the constructor with signature Mouse(int weight, String color).<br \/>\n<\/span><\/i><i><span style=\"font-weight: 400;\">We are in the constructor with signature Mouse(int weight, String color, String name).<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400;\">The third constructor will call the second constructor, then the second constructor will call the first constructor. The fist constructor will finish its work and, just after this, the message will be printed. After we will move to the second constructor, then to the third.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">We can call the constructor of a class from its <a href=\"https:\/\/www.h2kinfosys.com\/blog\/design-a-class-in-java\/\">superclass<\/a>:<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public class Animal {<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public Animal() {<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">System.out.println(\u201cIn the superclass.\u201d);<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public class Lion extends \u00a0Animal {<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public \u00a0Lion() {<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">super();<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">System.out.println(\u201cIn the subclass.\u201d);<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public class TestLion {<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public static void main(String[] args) {<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">Lion lion = new Lion();<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The output og this small application will be:<\/span><\/p>\n<p style=\"padding-left: 60px;\"><i><span style=\"font-weight: 400;\">In the superclass.<br \/>\n<\/span><\/i><i><span style=\"font-weight: 400;\">In the subclass.<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400;\">Let&#8217;s look at the wrong example of overloading our constructor:<\/span><\/p>\n<p style=\"padding-left: 60px;\"><i><span style=\"font-weight: 400;\">public Mouse(int weight) {}<br \/>\n<\/span><\/i><i><span style=\"font-weight: 400;\">public Mouse(int length) {} \/\/ DOES NOT COMPILE<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400;\">Changing the parameter name is not enough. It has to be a parameter with a different type.<br \/>\n<\/span><span style=\"font-weight: 400;\">Also, there is a tricky situation with varargs. This code does not compile:<\/span><\/p>\n<p style=\"padding-left: 60px;\"><i><span style=\"font-weight: 400;\">public Mouse(int[] parameters) {}<br \/>\n<\/span><\/i><i><span style=\"font-weight: 400;\">public Mouse(int&#8230; parameters) {} \/\/ DOES NOT COMPILE<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400;\">The method doesn&#8217;t look the same, but it compiles to the same parameter list. SO, we cannot do overloading like this.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0<\/span><span style=\"font-weight: 400;\">Here is one more interesting example of the overloading:<\/span><\/p>\n<p style=\"padding-left: 60px;\"><i><span style=\"font-weight: 400;\">public Mouse(int weight) {}<br \/>\n<\/span><\/i><i><span style=\"font-weight: 400;\">public Mouse(short weight) {} \/\/Will compile<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400;\">If we call<\/span><i><span style=\"font-weight: 400;\">\u00a0the new Mouse(50)<\/span><\/i><span style=\"font-weight: 400;\"> the constructor <\/span><i><span style=\"font-weight: 400;\">Mouse(int weight) <\/span><\/i><span style=\"font-weight: 400;\">will be called. To call constructor <\/span><i><span style=\"font-weight: 400;\">Mouse(short weight) <\/span><\/i><span style=\"font-weight: 400;\">you have to write <\/span><i><span style=\"font-weight: 400;\">new Mouse((short)50);<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400;\">A similar situation will be with this overloading:<\/span><\/p>\n<p style=\"padding-left: 60px;\"><i><span style=\"font-weight: 400;\">public Mouse(int weight) {}<br \/>\n<\/span><\/i><i><span style=\"font-weight: 400;\">public Mouse(long weight) {} \/\/Will compile<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400;\">To call the constructor with a parameter that has the\u00a0<\/span><i><span style=\"font-weight: 400;\">long <\/span><\/i><span style=\"font-weight: 400;\">type<\/span> <span style=\"font-weight: 400;\">you need to write:<\/span><\/p>\n<p style=\"padding-left: 60px;\"><i><span style=\"font-weight: 400;\">new Mouse(50L);<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400;\">Here is another example:<\/span><\/p>\n<p style=\"padding-left: 60px;\"><i><span style=\"font-weight: 400;\">public Mouse(int weight) {}<br \/>\n<\/span><\/i><i><span style=\"font-weight: 400;\">public Mouse(Integer length) {}\/\/Will compile<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400;\">In this case, code will compile. The situation will be the same as in the previous example. In the case of calling the\u00a0<\/span><i><span style=\"font-weight: 400;\">new Mouse(50)<\/span><\/i><span style=\"font-weight: 400;\">, the constructor <\/span><i><span style=\"font-weight: 400;\">Mouse(int weight) <\/span><\/i><span style=\"font-weight: 400;\">will be called. The autoboxing will have a place if the primitive <\/span><i><span style=\"font-weight: 400;\">int<\/span><\/i><span style=\"font-weight: 400;\"> version isn&#8217;t present. There is no reason for Java to do the extra work when the primitive <\/span><i><span style=\"font-weight: 400;\">int<\/span><\/i><span style=\"font-weight: 400;\"> version is provided.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">In Java language, a constructor cannot be with modifiers abstract, static, final, and synchronized, but can be with all kinds of access modifiers. Interesting that class can have several constructors and each can have its own access modifier. Usually, constructors are declared with modifier <\/span><i><span style=\"font-weight: 400;\">public<\/span><\/i><span style=\"font-weight: 400;\">.\u00a0 If a constructor is <\/span><i><span style=\"font-weight: 400;\">protected<\/span><\/i><span style=\"font-weight: 400;\"> then it can be only accessed by classes in the same package or subclasses of that class.\u00a0<\/span><\/p>\n<p dir=\"ltr\"><span style=\"font-weight: 400;\">Private constructors are widely used when you need to have just one instance of your class. It is called <\/span><i><span style=\"font-weight: 400;\">Singleton<\/span><\/i><span style=\"font-weight: 400;\">.\u00a0 In this case, you need to create a static method that will return your object, because the constructor is private and you cannot call it from another class. Usually, as the name of that static method is used getInstance(). Here is an example:<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public class Zoo {<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\/\/variable for single instance of \u00a0our class Zoo<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">private static Zoo zoo;<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\/\/private constructor\u00a0<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">private Zoo() {<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\u00a0<\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">System.out.println(\u201cOne instance of Zoo is created\u201d);<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\/\/ method to get instance of our Zoo<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public static Zoo getInstance() {<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">if(zoo == null) {<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">zoo = new Zoo();<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">return zoo;<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">} \u00a0<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public class TestSingleton {<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public static void main (String[] args) {<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">Zoo zoo1 = Zoo.getInstance();<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">Zoo zoo2 = Zoo.getInstance();<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">Zoo zoo3 = Zoo.getInstance();<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">As you see, we will create a new instance of class Zoo just in case we don&#8217;t have one already created. The output of current code will be <\/span><i><span style=\"font-weight: 400;\">\u201cOne instance of Zoo is created\u201d. <\/span><\/i><span style=\"font-weight: 400;\">And it will be printed just one time.<\/span><\/p>\n<h2><b>Throwing Exceptions From a Constructor.\u00a0<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">We can throw exceptions from a constructor and it is legal. Here is an example:<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public class Rabbit throws Exception {<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public Rabbit(String name) {<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">if (name == null) {<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">new Exception (\u201cThe name parameter cannot be null!\u201d)<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p>&nbsp;<\/p>\n<p dir=\"ltr\">An Exception is a part of a constructor&#8217;s declaration. Let&#8217;s look at the example of calling constructor:<\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public class TestRabbit {<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">public static void main (String[] args) {<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">Rabbit rabbit = null;<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">String name = \u201cBunny\u201d;<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">try {<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">rabbit = new Rabbit(name);<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">} catch(Exception exception) {<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">\/\/handle exception\u00a0<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1; margin-top: 0pt; margin-bottom: 0pt; padding-left: 60px;\"><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span class=\"Apple-tab-span\" style=\"white-space: pre;\">\u00a0 \u00a0\u00a0<\/span><\/span><span style=\"font-size: 12pt; font-family: 'Times New Roman'; color: #000000; background-color: transparent; font-weight: 400; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">}<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>If a variable\u00a0name\u00a0is\u00a0null,\u00a0not the\u00a0\u201cBunny\u201d,\u00a0the exception will be thrown from the constructor, and an instance of class Rabbit will not be created, and the variable\u00a0rabbit\u00a0will\u00a0remain\u00a0null.\u00a0The throwing of exceptions prevents the creation of an invalid object.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Constructor is a special method that has no return type and matches the name of the class. They are using for the creation of new objects. For example:\u00a0 public class Fish { public Fish() { System.out.println(&#8220;constructor&#8221;); } }\u00a0 The creation of new object is called instantiation, because it creates a new instance of the class. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2406,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[42],"tags":[445,58,446],"class_list":["post-2236","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java-tutorials","tag-constructors","tag-java","tag-overloading"],"_links":{"self":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts\/2236","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/comments?post=2236"}],"version-history":[{"count":0,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts\/2236\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/media\/2406"}],"wp:attachment":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/media?parent=2236"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/categories?post=2236"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/tags?post=2236"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}