{"id":79148,"date":"2020-06-22T09:00:31","date_gmt":"2020-06-22T03:30:31","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=79148"},"modified":"2020-06-22T09:00:31","modified_gmt":"2020-06-22T03:30:31","slug":"implements-in-java","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/implements-in-java\/","title":{"rendered":"Learn Everything About Implements in Java"},"content":{"rendered":"<p>In the previous Tutorial of Java, we discussed the Keyword extends in Java. In this article, we have come up with the <strong>Keyword implements in Java<\/strong>. We will learn what is an implements keyword in Java and where and how we can use it in Java programs.<\/p>\n<p>We will discuss implements in java with examples and programs to learn the concept better.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/06\/Implements-keyword-in-java.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-79170\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/06\/Implements-keyword-in-java.jpg\" alt=\"Implements keyword in java\" width=\"802\" height=\"420\" \/><\/a><\/p>\n<h3>Implements Keyword in Java<\/h3>\n<p>Java implements keyword is another reserved word in Java that conveys special meaning to the compiler. The implements keyword is useful when we want to use an interface in the class. In short, the implements keyword is useful to implement the interfaces in classes.<\/p>\n<p>We know that an interface in Java is defined as a special type of class that only contains abstract methods inside it; the methods which do not have any implementation or body inside them. It just provides a plan, contract, or a prototype that the classes must follow.<\/p>\n<p>The implements keyword is used by a class so that it can follow or adhere to the contract provided by the interface. The class that implements the interface must provide the concrete implementation of all the methods declared in the interface by providing the method body to the methods.<\/p>\n<p>And, if the class does not provide the implementation of these methods, then it must declare as abstract, otherwise, there will be a compilation error.<\/p>\n<h3>Examples of Java Implements<\/h3>\n<p>Before moving to the examples of the implements keyword, let\u2019s see the syntax of using this keyword:<\/p>\n<p><strong>Syntax of using implements keyword in java:<\/strong><\/p>\n<p><strong>1. Interface:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">interface InterfaceName {\n  \/\/Abstract methods\n}<\/pre>\n<p><strong>2. Class:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">class MyClass implements InterfaceName {\n  \/\/Implementation of all the methods declared in the interface\n}<\/pre>\n<p>Let\u2019s see an example code to understand the use of implements keyword:<\/p>\n<p><strong>Code to understand the implements keyword:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.techvidvan.implementskeyword;\n\/\/Defining the Shape interface\ninterface Shape {\n  \/\/declaring an abstract method of the interface\n  public double getArea();\n}\n\/\/class implements the Shape interface using the implements keyword\nclass Circle implements Shape {\n  public double radius = 5;\n  public double getArea() {\n    return 3.142 * radius * radius;\n  }\n}\nclass Rectangle implements Shape {\n  public double length = 5;\n  public double breadth = 10;\n\n  \/\/providing implementation to the interface methods\n  public double getArea() {\n    return length * breadth;\n  }\n}\npublic class Demo {\n  public static void main(String args[]) {\n    Circle c = new Circle();\n    double circleArea = c.getArea();\n    System.out.println(\"Area of Circle is: \" + circleArea);\n    Rectangle r = new Rectangle();\n    double rectangleArea = r.getArea();\n    System.out.println(\"Area of Rectangle is: \" + rectangleArea);\n  }\n}<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">Area of Circle is: 78.55<br \/>\nArea of Rectangle is: 50.0<\/div>\n<p><strong>Example 2:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.techvidvan.implementskeyword;\n\/\/Defining an interface\ninterface Calculator {\n  \/\/Declaring method of the interface\n  public void addition(int a, int b);\n  public void subtraction(int a, int b);\n}\n\nclass Calci implements Calculator {\n  \/\/implemeting the methods of the interface\n  public void addition(int a, int b) {\n    System.out.println(\"Addition: \" + (a + b));\n  }\n\n  public void subtraction(int a, int b) {\n    System.out.println(\"Subtraction: \" + (a - b));\n  }\n}\n\npublic class MyCalci {\n  public static void main(String[] args) {\n    Calci calci = new Calci();\n    calci.addition(5, 4);\n    calci.subtraction(9, 4);\n  }\n}<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">Addition: 9<br \/>\nSubtraction: 5<\/div>\n<h3>Multiple Interfaces in Java<\/h3>\n<p>Java interface contains the Variables and Methods the same as the class but unlike a class, the interface has undefined methods i.e. methods without any definition. Java Programming Language also provides the feature of defining multiple interfaces in the same program.<\/p>\n<p>Interface in Java is implemented by another class. We created a program that only contains the interface as a communication bridge.<\/p>\n<p>Java does not support multiple inheritances with classes and this feature can implement using multiple interfaces in Java. The following program explains the concept of multiple Interfaces.<\/p>\n<p><strong>Code to explain Java multiple interfaces:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.techvidvan.implementskeyword;\ninterface MachineOn {\n  void onMechanism();\n}\ninterface MachineOff {\n  void offMechanism();\n}\n\/\/Implementing multiple interfaces\nclass Machine implements MachineOn,\nMachineOff {\n  public void onMechanism() {\n    System.out.println(\"Machine is ON\");\n  }\n\n  public void offMechanism() {\n    System.out.println(\"Machine is OFF\");\n  }\n}\npublic class MyExample {\n  public static void main(String args[]) {\n    Machine m = new Machine();\n    m.onMechanism();\n    m.offMechanism();\n  }\n}<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">Machine is ON<br \/>\nMachine is OFF<\/div>\n<h3>Conclusion<\/h3>\n<p>So, this was all about the implements keyword in Java. The implements keyword enables a class to use the contract defined by the interfaces in Java. The class provides the actual implementation of the interface.<\/p>\n<p>We discussed two example programs that make the use of the implements keyword in Java. The class can also implement multiple interfaces using the implements keyword and the example for the same has also been covered in the article.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the previous Tutorial of Java, we discussed the Keyword extends in Java. In this article, we have come up with the Keyword implements in Java. We will learn what is an implements keyword&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":79170,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[183],"tags":[2908,2909,2328,2910],"class_list":["post-79148","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","tag-implements-in-java","tag-java-implement-interface","tag-java-implements","tag-java-implements-keyword"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Learn Everything About Implements in Java - TechVidvan<\/title>\n<meta name=\"description\" content=\"Learn what is Keyword Implements in java with syntax, examples and programs. Learn Multiple interfaces in java with example.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/implements-in-java\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Learn Everything About Implements in Java - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Learn what is Keyword Implements in java with syntax, examples and programs. Learn Multiple interfaces in java with example.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/implements-in-java\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-06-22T03:30:31+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/06\/Implements-keyword-in-java.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"802\" \/>\n\t<meta property=\"og:image:height\" content=\"420\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Learn Everything About Implements in Java - TechVidvan","description":"Learn what is Keyword Implements in java with syntax, examples and programs. Learn Multiple interfaces in java with example.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/techvidvan.com\/tutorials\/implements-in-java\/","og_locale":"en_US","og_type":"article","og_title":"Learn Everything About Implements in Java - TechVidvan","og_description":"Learn what is Keyword Implements in java with syntax, examples and programs. Learn Multiple interfaces in java with example.","og_url":"https:\/\/techvidvan.com\/tutorials\/implements-in-java\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2020-06-22T03:30:31+00:00","og_image":[{"width":802,"height":420,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/06\/Implements-keyword-in-java.jpg","type":"image\/jpeg"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/implements-in-java\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/implements-in-java\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"Learn Everything About Implements in Java","datePublished":"2020-06-22T03:30:31+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/implements-in-java\/"},"wordCount":483,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/implements-in-java\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/06\/Implements-keyword-in-java.jpg","keywords":["Implements in Java","java implement interface","Java Implements","java implements keyword"],"articleSection":["Java Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/implements-in-java\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/implements-in-java\/","url":"https:\/\/techvidvan.com\/tutorials\/implements-in-java\/","name":"Learn Everything About Implements in Java - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/implements-in-java\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/implements-in-java\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/06\/Implements-keyword-in-java.jpg","datePublished":"2020-06-22T03:30:31+00:00","description":"Learn what is Keyword Implements in java with syntax, examples and programs. Learn Multiple interfaces in java with example.","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/implements-in-java\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/implements-in-java\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/implements-in-java\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/06\/Implements-keyword-in-java.jpg","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/06\/Implements-keyword-in-java.jpg","width":802,"height":420,"caption":"Implements keyword in java"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/implements-in-java\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Learn Everything About Implements in Java"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/79148","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=79148"}],"version-history":[{"count":0,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/79148\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/79170"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=79148"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=79148"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=79148"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}