{"id":641,"date":"2012-09-06T01:54:21","date_gmt":"2012-09-06T01:54:21","guid":{"rendered":"http:\/\/codeatelier.wordpress.com\/?p=280"},"modified":"2012-09-06T01:54:21","modified_gmt":"2012-09-06T01:54:21","slug":"constructors-in-java","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/constructors-in-java\/","title":{"rendered":"Constructors in java"},"content":{"rendered":"<p><strong>Method name same as Class Name<\/strong><br \/>\nvoid Sample3 is a method not a Constructor<\/p>\n<pre>\npackage com.scjp.test;\n\npublic class Sample3 \n{\t\n\tvoid Sample3()\n\t{\n\t\tSystem.out.println(\"I am Constructor\");\n\t}\n\tpublic static void main(String[] args) \n\t{\n\t\tSample3 objSample3 = new Sample3();\n\t}\n}\n<\/pre>\n<p>OP:<\/p>\n<p><strong>Overloading Constructors<\/strong><\/p>\n<pre>\npackage com.scjp.test;\n\nclass Sample3\n{\n  public static void main(String args[])\n  {\n    Vasko objVasko1 = new Vasko(54);\n    Vasko objVasko2 = new Vasko();\n    System.out.println(objVasko1.Size);\n    System.out.println(objVasko2.Size);\n  }\t\n}\n\nclass Vasko\n{\n   int Size;\n\n   Vasko()\n   {\t  \n   }\n\t\n   Vasko(int s)\n   {\n    Size = s;\t  \n   }\n}\n<\/pre>\n<p>OP:<\/p>\n<pre>\n54\n0\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Method name same as Class Name void Sample3 is a method not a Constructor package com.scjp.test; public class Sample3 { void Sample3() { System.out.println(&#8220;I am Constructor&#8221;); } public static void main(String[] args) { Sample3 objSample3 = new Sample3(); } } OP: Overloading Constructors package com.scjp.test; class Sample3 { public static void main(String args[]) { Vasko&hellip; <a href=\"https:\/\/codethataint.com\/blog\/constructors-in-java\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-641","post","type-post","status-publish","format-standard","hentry","category-java"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/641","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/comments?post=641"}],"version-history":[{"count":0,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/641\/revisions"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=641"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=641"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=641"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}