{"id":700,"date":"2010-08-02T19:54:08","date_gmt":"2010-08-02T14:24:08","guid":{"rendered":"http:\/\/JitendraZaa.com\/blog\/?p=700"},"modified":"2010-08-02T19:54:08","modified_gmt":"2010-08-02T14:24:08","slug":"interface","status":"publish","type":"post","link":"https:\/\/www.jitendrazaa.com\/blog\/java\/interface\/","title":{"rendered":"Interface in JAVA"},"content":{"rendered":"<p><strong>Interface &amp; Its Advantage:-<\/strong><\/p>\n<p>1. If all the methods in the class is abstract then the class is nothing but the <strong>interface<\/strong>.<\/p>\n<p>2. We <strong>cannot create an object<\/strong> of interface.<\/p>\n<p>3. To implement the interface by child class keyword <strong>&#8220;implements&#8221;\u009d<\/strong> is used.<\/p>\n<p>4. Interface is defined by using keyword <strong>interface.<\/strong><\/p>\n<p>5. If a <strong>class implements interface but does not implements methods, then the<\/strong> <strong>class<\/strong> is abstract class.<\/p>\n<p>6. We can assign the <strong>object of class which implements the interface<\/strong> of type of \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0that interface.<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\ninterface Duck\n{\n    Void DuckType();\n    Void DuckProperty();\n}\n\nclass BlackDuck implements Duck\n{\n Public void DuckType()\n {\n     System.out.println(\"Black Duck\"\u009d);\n }\n\n Public void DuckProperty()\n {\n   System.out.println(\"Swim, Quack \u00a0and Fly\"\u009d);\n }\n }\n\nclass TestDuck\n{\n Public static void main(String args&#x5B;])\n {\n     BlackDuck obj=new BlackDuck();\n     Obj.DuckType();\n     Obj.DuckProperty();\n }\n}\n<\/pre>\n<p><strong>Advantages of Interface:-<\/strong><\/p>\n<ul>\n<li>Runtime Polymorphism<\/li>\n<li>Contract can be used throughout the application<\/li>\n<\/ul>\n<p><a title=\"Inheritance, interface and abstract class\" href=\"https:\/\/jitendrazaa.com\/blog\/java\/difference-between-interfaceinheritance-abstract-class\/\" target=\"_blank\">To know more about inheritance and abstract classes, refer this article.<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Explains the usage and benefits of interface in JAVA.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"jz_research_post":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3],"tags":[122],"class_list":["post-700","post","type-post","status-publish","format-standard","hentry","category-java","tag-interface"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":702,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/difference-between-interfaceinheritance-abstract-class\/","url_meta":{"origin":700,"position":0},"title":"Interface, Inheritance and abstract class","author":"Jitendra","date":"August 6, 2010","format":false,"excerpt":"What is abstract class, interface and inheritance in java. Source code and example","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/"},"img":{"alt_text":"Inheritance, Interface and abstract class","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2010\/08\/Inheritance1-300x173.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":2049,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/explain-externalizable-in-java\/","url_meta":{"origin":700,"position":1},"title":"Explain Externalizable in Java","author":"Jitendra","date":"April 20, 2011","format":false,"excerpt":"Explain Externalizable in Java","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":757,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/anonymous-classimplements-interface-methods-of-threads\/","url_meta":{"origin":700,"position":2},"title":"Create Thread using Anonymous class and Interface","author":"Jitendra","date":"August 16, 2010","format":false,"excerpt":"Demonstration of creating Thread by Anonymous class and Interface","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1820,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/java-threading-executor-framework-and-callable-interface\/","url_meta":{"origin":700,"position":3},"title":"Java Threading &#8211; Executor Framework and Callable Interface","author":"Jitendra","date":"March 24, 2011","format":false,"excerpt":"Java Threading - Executor Framework and Callable Interface with example","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1612,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/serialization-marshalling-deflating-in-java\/","url_meta":{"origin":700,"position":4},"title":"Serialization \/ Marshalling \/ Deflating in JAVA","author":"Jitendra","date":"March 9, 2011","format":false,"excerpt":"Concept of Serialization \/ Marshalling \/ Deflating in JAVA","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/"},"img":{"alt_text":"Serialization ,Marshalling ,deflating, DeSerialization ,UnMarshalling ,inflating","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/03\/Serialization-Marshalling-deflating-DeSerialization-UnMarshalling-inflating.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":2017,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/java-j2ee-interview-questions-1\/","url_meta":{"origin":700,"position":5},"title":"Java &#8211; J2EE Interview Questions &#8211; 1","author":"Jitendra","date":"April 15, 2011","format":false,"excerpt":"JAVA - J2EE Interview Questions - 1, JAVA - J2EE Interview Questions - 1,custom tag JSP, Externalization , serialVersionUID, difference between interface and abstract class, iterate HashMap","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/700","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/comments?post=700"}],"version-history":[{"count":0,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/700\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/media?parent=700"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/categories?post=700"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/tags?post=700"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}