{"id":4415,"date":"2014-03-30T10:45:12","date_gmt":"2014-03-30T10:45:12","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/static-binding-and-dynamic-binding-collection-of-common-programming-errors\/"},"modified":"2014-03-30T10:45:12","modified_gmt":"2014-03-30T10:45:12","slug":"static-binding-and-dynamic-binding-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/static-binding-and-dynamic-binding-collection-of-common-programming-errors\/","title":{"rendered":"Static Binding and Dynamic Binding-Collection of common programming errors"},"content":{"rendered":"<p>Your current code will output <code>Animal is eating<\/code><\/p>\n<p>However, in your main class, if you created an object of type <code>Dog<\/code> and assigned it to <code>Animal<\/code>, then your output will be <code>Dog is eating<\/code> due to dynamic binding.<\/p>\n<pre><code>public static void main(String args[])\n{\n    Animal a = new Dog(); \/\/ An object of Dog is assigned to Animal\n    a.eat(); \/\/ Dynamically determines which eat() method to call\n}\n<\/code><\/pre>\n<p>Even though <code>a<\/code> is declared as <code>Animal<\/code> it is pointing to an object of type <code>Dog<\/code>. So, at runtime, the object type is determined and appropriate <code>eat()<\/code> method is called.<\/p>\n<p>One way to think of it is, <code>method overloading<\/code> is statically bound and <code>method overriding<\/code> is dynamically bound.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Your current code will output Animal is eating However, in your main class, if you created an object of type Dog and assigned it to Animal, then your output will be Dog is eating due to dynamic binding. public static void main(String args[]) { Animal a = new Dog(); \/\/ An object of Dog is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4415","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4415","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4415"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4415\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4415"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4415"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4415"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}