{"id":1506,"date":"2022-03-05T06:26:56","date_gmt":"2022-03-05T06:26:56","guid":{"rendered":"https:\/\/mdr.foobrdigital.com\/?p=1506"},"modified":"2022-03-05T06:26:56","modified_gmt":"2022-03-05T06:26:56","slug":"what-is-the-purpose-of-a-default-constructor","status":"publish","type":"post","link":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/2022\/03\/05\/what-is-the-purpose-of-a-default-constructor\/","title":{"rendered":"What is the purpose of a default constructor?"},"content":{"rendered":"\n<p>The purpose of the default constructor is to assign the default value to the objects. The java compiler creates a default constructor implicitly if there is no constructor in the class.<a href=\"https:\/\/www.javatpoint.com\/corejava-interview-questions#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/corejava-interview-questions#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/corejava-interview-questions#\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Student3{  \nint id;  \nString name;  \n  \nvoid display(){System.out.println(id+\" \"+name);}  \n  \npublic static void main(String args&#91;]){  \nStudent3 s1=new Student3();  \nStudent3 s2=new Student3();  \ns1.display();  \ns2.display();  \n}  \n}  <\/code><\/pre>\n\n\n\n<p>Output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>0 null\n0 null\n<\/code><\/pre>\n\n\n\n<p><strong>Explanation:<\/strong>&nbsp;In the above class, you are not creating any constructor, so compiler provides you a default constructor. Here 0 and null values are provided by default constructor.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/static.javatpoint.com\/images\/default-constructor1.png\" alt=\"Java default constructor\"\/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>The purpose of the default constructor is to assign the default value to the objects. The java compiler creates a default constructor implicitly if there is no constructor in the class. Output: Explanation:&nbsp;In the above class, you are not creating any constructor, so compiler provides you a default constructor. Here 0 and null values are [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[437],"tags":[],"_links":{"self":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/1506"}],"collection":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/comments?post=1506"}],"version-history":[{"count":0,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/1506\/revisions"}],"wp:attachment":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/media?parent=1506"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/categories?post=1506"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/tags?post=1506"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}