

{"id":8106,"date":"2018-02-15T08:57:59","date_gmt":"2018-02-15T08:57:59","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=8106"},"modified":"2026-05-18T16:43:03","modified_gmt":"2026-05-18T11:13:03","slug":"interface-in-java","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/interface-in-java\/","title":{"rendered":"Interface in Java &#8211; Explore Difference Between Classes and Interfaces"},"content":{"rendered":"<p>We have learned about interfaces in the article \u201cAbstraction in Java\u201d. In this article, we will take a deeper look at interfaces in Java. Let us look at a real-life example for interfaces.<\/p>\n<p>You must know about simple interests from school arithmetic. You also must know about the formula for calculating the simple interest for a given principal amount. But consider the case of different banks throughout the world. They calculate the simple interest by the same formula, but they have their own rates of interest. Hence, the same method name would be useful to the banks, but their implementations would be completely different.<\/p>\n<p>Now, let us assume that a computer has the prototype of the function that calculates interest. This computer does not have the implementation of the function. It simply knows that there is a function that is useful for calculating interest. This computer is now an interface.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Interfaces-in-Java-df.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-84380\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Interfaces-in-Java-df.jpg\" alt=\"Interface in Java\" width=\"1200\" height=\"628\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Interfaces-in-Java-df.jpg 1200w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Interfaces-in-Java-df-300x157.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Interfaces-in-Java-df-1024x536.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Interfaces-in-Java-df-150x79.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Interfaces-in-Java-df-768x402.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Interfaces-in-Java-df-720x377.jpg 720w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Interfaces-in-Java-df-520x272.jpg 520w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Interfaces-in-Java-df-320x167.jpg 320w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/a><\/p>\n<h3>Interface in Java<\/h3>\n<p>Interfaces in Java are similar to abstract classes, but with some key differences. These are essential for defining a blueprint of the class methods. It is one of the methods programmers use to achieve abstraction. Interface contains the common methods that are to be used by different classes.<\/p>\n<ul>\n<li>Interfaces store specifications and details about a class. They contain information about the class behavior<\/li>\n<li>It contains all the functions that a class can perform. For example, an interface for a car would have break(), accelerate(), and turn() methods.<\/li>\n<li>A class, while implementing an interface, must implement all the methods inside the interface. However, it can choose not to implement all the methods if the class itself is abstract.<\/li>\n<li>One of the popular interfaces in Java is the Comparator interface. which is useful for sorting containers.<\/li>\n<\/ul>\n<h3>Why use Java Interfaces?<\/h3>\n<p>Interfaces are useful for a variety of reasons in Java. They are:<\/p>\n<ul>\n<li>To achieve loose coupling by minimizing the dependencies within the classes and their variables.<\/li>\n<li>To implement multiple inheritance in Java, an interface allows a class to inherit the properties of two or more interfaces.<\/li>\n<li>For achieving abstraction in your programs by showing only necessary details and hiding the implementation logic.<\/li>\n<\/ul>\n<h3>Declaring Interface in Java<\/h3>\n<p>The syntax for using interfaces is simple. For declaring an interface,<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">interface &lt;interface_name&gt;\r\n{\r\n\/\/Method names\r\n}\r\n<\/pre>\n<h3>Interface Variables in Java<\/h3>\n<p>Interfaces can contain variables. However, it is redundant to declare variables inside interfaces because the class can contain the same variables. Whenever you declare a variable inside an interface, the variable automatically becomes public, static, and final. It is advisable not to use interface variables in Java.<\/p>\n<h3>Interface Methods in Java<\/h3>\n<p>Interface methods are essential because they are redefined in the classes. They do not contain method bodies. They simply contain the access specifier, the name, the return type, and the parameters to the function. These are similar to abstract methods we learned about in the previous lesson on abstraction in Java.<\/p>\n<p>We will see an example of interface variables and methods while implementing interfaces in Java. All of the methods in an interface are public.<\/p>\n<h3>Implementing Interfaces in Java<\/h3>\n<p>When we want to implement an interface in a class, we use the following syntax.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">class &lt;class_name&gt; implements &lt;interface_name&gt;\r\n<\/pre>\n<p>Once you implement interfaces, you should define all the methods inside the interface or declare the class implementing the interface as abstract.<\/p>\n<p><strong>Java program to illustrate the use of interfaces in Java:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.dataflair.interfaces;\r\ninterface ShootType {\r\n  \/\/This interface houses all the methods which will be implemented in the program. \r\n  public void shoot();\r\n}\r\nclass Father implements ShootType {\r\n  public void shoot() {\r\n    \/\/First implementation of the method shoot()\r\n    System.out.println(\"I am the father and I shoot with my right hand!\");\r\n  }\r\n}\r\nclass Son implements ShootType {\r\n  public void shoot() {\r\n    \/\/second implementation of the method shoot. \r\n    System.out.println(\"I am the son. My father uses the right hand to shoot. I use my left hand to shoot!\");\r\n  }\r\n}\r\npublic class InterfacesJava {\r\n  public static void main(String[] args) {\r\n    Father f = new Father();\r\n    Son s = new Son();\r\n    f.shoot();\r\n    s.shoot();\r\n  }\r\n}<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">I am the father and I shoot with my right hand!<br \/>\nI am the son. My father uses the right hand to shoot. I use my left hand to shoot!<\/div>\n<h3>Extending Multiple Inheritance in Java<\/h3>\n<p>You cannot implement multiple inheritance in Java by using the extends keyword. However, you can use interfaces to implement multiple inheritance. How? We will see an example<\/p>\n<p><strong>Java program to illustrate the implementation of multiple inheritance by using interfaces:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.dataflair.interfaces;\r\ninterface Accelerate {\r\n  public void acceleratemethod();\r\n}\r\ninterface Brake {\r\n  public void brakemethod();\r\n}\r\nclass Car implements Accelerate,\r\nBrake {\r\n  public void brakemethod() {\r\n    System.out.println(\"This car has disc brakes\");\r\n  }\r\n  public void acceleratemethod() {\r\n    System.out.println(\"This car has BENZ OM654 engine with 503 HP\");\r\n  }\r\n}\r\nclass MultipleInheritance {\r\n  public static void main(String[] args) {\r\n    Car carobject = new Car();\r\n    carobject.acceleratemethod();\r\n    carobject.brakemethod();\r\n  }\r\n}<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">This car has BENZ OM654 engine with 503 HP<br \/>\nThis car has disc brakes<\/div>\n<p>We observe that the two interfaces act as abstract classes. This is similar to extending two abstract classes inside a third class. This is how we implement multiple inheritance in Java.<\/p>\n<h3>Tag Interface or Empty Interface in Java<\/h3>\n<p>These are the interfaces that do not have any methods or variables within it. They are empty interfaces. One popular example of such an interface is the Serializable interface. Well, if they are empty, why are they useful? You might be thinking. These are not useful for the programmer; rather, it is useful for the JVM(Java Virtual Machine) to assign the class to a particular type.<\/p>\n<p>For example, the Serializable interface is a popular interface in Java. But it is empty. Whenever a class implements this interface, the JVM understands the class is going to perform Serialization inside it.<\/p>\n<p><strong>In general, Tag interfaces look like this:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">interface &lt;interface_name&gt;\r\n{}\r\n<\/pre>\n<h3>Java Nested Interface<\/h3>\n<p>As the name suggests, nested interfaces are interfaces within interfaces. You can now group similar interfaces inside one single interface. Once grouped, we can use the dot(.) operator to call nested interfaces,<\/p>\n<p><strong>Nested interfaces are of two types:<\/strong><\/p>\n<ol>\n<li>Inside another interface<\/li>\n<li>Inside a class<\/li>\n<\/ol>\n<p><strong>Java program to illustrate the use of nested interfaces inside an interface:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.dataflair.interface;\r\ninterface OuterInterface {\r\n  void display();\r\n  interface InnerInterface {\r\n    void myMethod();\r\n  }\r\n}\r\n\r\nclass NestedInterface implements OuterInterface.InnerInterface {\r\n  public void myMethod() {\r\n    System.out.println(\"This is the nested interface method\");\r\n  }\r\n\r\n  public static void main(String args[]) {\r\n    NestedInterface object = new NestedInterface();\r\n    object.myMethod();\r\n  }\r\n}<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">This is the nested interface method<\/div>\n<p><strong>Java program to illustrate the use of nested interfaces inside a class:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.dataflair.interface;\r\nclass InterfaceClass {\r\n  interface InnerInterface {\r\n    void myMethod();\r\n  }\r\n}\r\n\r\nclass NestedInterface implements InterfaceClass.InnerInterface {\r\n  public void myMethod() {\r\n    System.out.println(\"This is the nested interface method in the class. \");\r\n  }\r\n\r\n  public static void main(String args[]) {\r\n    NestedInterface object = new NestedInterface();\r\n    object.myMethod();\r\n  }\r\n}<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">This is the nested interface method in the class.<\/div>\n<h3>Properties of Java Interface<\/h3>\n<ul>\n<li>You have to implement all the methods of the interface inside the class unless the class itself is an abstract class.<br \/>\nIf the class is an abstract class, then you need not define all the methods in the interface. But you have to do so when you inherit the abstract class inside the main class.<\/li>\n<li>Interfaces can have public, static, and final variables only.<br \/>\nYou can extend interfaces but you cannot implement them.<\/li>\n<li>If two interfaces have the same method and a class implements both the interfaces, then the class has to implement the common method once.<\/li>\n<li>If two different interfaces have the same method name but different return types a class will not be able to implement them.<\/li>\n<li>However, both interfaces can have the same variable name. The variable is then accessible by &lt;interface_name&gt;.&lt;variable_name&gt;.<\/li>\n<\/ul>\n<p>With the advent of new Java versions throughout the years, a lot of new features have come into being. Let us look at some of them!<\/p>\n<h3>New Features of Interfaces: Default, Private, and Static Methods in Interfaces<\/h3>\n<ul>\n<li>If you are using Java version 8 or newer, you can add default implementations to your interfaces. Default implementations of functions are useful because a concrete class may not provide a specific implementation of that method. This prevents the old code from breaking if a new method is added to the interface.<\/li>\n<li>You can also have static methods inside an interface, which you can call without an object. However, these methods are non-inheritable.<\/li>\n<li>If you are using Java 9 or newer, you can have static, private, and private static methods inside your interface.<\/li>\n<\/ul>\n<p>Let us look at an example program to understand the new features of Java.<\/p>\n<h4>Java Interface Static Methods<\/h4>\n<p>Interfaces can have static methods, which are useful when you need to call a method directly from an interface without implementing it. You can simply call a static method of an interface the same way you call a static method inside a class.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;Interface_name&gt;.&lt;method_name&gt;\r\n<\/pre>\n<p><strong>Java program to illustrate the use of interface static methods:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.dataflair.interfaces;\r\ninterface Vehicle {\r\n  public void accelerate();\r\n  public static void brake() {\r\n    System.out.println(\"This is a static method for braking\");\r\n  }\r\n}\r\n\r\npublic class InterfaceStatic implements Vehicle {\r\n  public void accelerate() {\r\n    System.out.println(\"This is a nonstatic method for implementing acceleration in cars\");\r\n  }\r\n  public static void main(String[] args) {\r\n    InterfaceStatic object = new InterfaceStatic();\r\n    object.accelerate();\r\n    Vehicle.brake();\r\n    System.out.println(\"Classic example of static methods in Interfaces\");\r\n  }\r\n}\r\n\r\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">This is a nonstatic method for implementing acceleration in cars<br \/>\nThis is a static method for braking<br \/>\nClassic example of static methods in Interfaces<\/div>\n<p><strong>Java program to illustrate the use of new features of interfaces:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.dataflair.interfaces;\r\ninterface InterfaceJava {\r\n  void run();\r\n  static void StaticMethod() \/\/static method\r\n  {\r\n    System.out.println(\"This is a static method\");\r\n\r\n  }\r\ndefault void sleep() \/\/default method\r\n  {\r\n    System.out.println(\"Both humans and dogs love to sleep\");\r\n  }\r\n}\r\nclass Dog implements InterfaceJava {\r\n  public void run() {\r\n    System.out.println(\"A dog runs with the help of four legs\");\r\n  }\r\n\r\n}\r\nclass Human implements InterfaceJava {\r\n  public void run() {\r\n    System.out.println(\"A human runs with the help of two legs\");\r\n  }\r\n}\r\nclass Interface {\r\n  public static void main(String[] args) {\r\n    Dog dog = new Dog();\r\n    dog.run();\r\n    Human human = new Human();\r\n    human.run();\r\n    InterfaceJava.StaticMethod();\r\n    human.sleep();\r\n\r\n  }\r\n}<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">A dog runs with the help of four legs<br \/>\nA human runs with the help of two legs<br \/>\nThis is a static method<br \/>\nBoth humans and dogs love to sleep<\/div>\n<h3>Advantages of Java Interface<\/h3>\n<ul>\n<li>Interfaces allow us to implement multiple inheritance in Java<\/li>\n<li>You can break up the complex design of the codebase with the help of interfaces.<\/li>\n<li>You also can easily clear dependencies between different objects,<\/li>\n<li>Interfaces promote loose coupling.<\/li>\n<\/ul>\n<h3>Disadvantages of Interface in Java<\/h3>\n<p>Although interfaces are extremely useful in programming, they have some disadvantages too. Some of them are:<\/p>\n<ul>\n<li>They are slow and limited in functionality.<\/li>\n<li>They bring down the execution speed of the program.<\/li>\n<li>The use of interfaces in programming is either minimal or extremely frequent, both of which destroy the functionality of the program.<\/li>\n<\/ul>\n<h3>Similarities and Differences Between Classes and Interfaces in Java<\/h3>\n<p>There are a lot of similarities in between classes and interfaces in Java. Some of them are :<\/p>\n<ul>\n<li>Both of them can contain methods and variables.<\/li>\n<li>You can see that the bytecode of an interface appears in the .class file.<\/li>\n<li>The directory structure of interfaces must be the same as the packages they are in.<\/li>\n<\/ul>\n<p>However, there are some striking differences between interfaces and class. They are:<\/p>\n<ul>\n<li>You cannot create an object of an interface.<\/li>\n<li>Any field that is inside an interface must be static and final. You cannot declare a field of any other type in an interface.<\/li>\n<li>A single interface can extend multiple interfaces. This is something that a class in Java cannot do.<\/li>\n<li>An interface in Java gets implemented, whereas a class gets extended in Java.<\/li>\n<\/ul>\n<h3>Relationship Between Class and Interface in Java<\/h3>\n<table>\n<tbody>\n<tr>\n<td><b>Class<\/b><\/td>\n<td><b>Interfaces<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">A class contains the functions and the variables. It is an individual datatype in itself.\u00a0<\/span><\/td>\n<td><span style=\"font-weight: 400\">An interface only contains the behavior of the class.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">A class can have concrete methods or abstract methods.\u00a0<\/span><\/td>\n<td><span style=\"font-weight: 400\">Until the release of the latest Java version, interfaces could not have concrete methods. Now they can have default methods.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Classes can have default, public, private and protected members.\u00a0<\/span><\/td>\n<td><span style=\"font-weight: 400\">Interfaces can have public, static, and final variables only.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Java Types that can Implement Interfaces<\/h3>\n<p>There are a few types of data types that can implement interfaces inside them. They are mentioned below:<\/p>\n<p><strong>1. Java Enums<\/strong><\/p>\n<p><strong>2. Java Dynamic Proxy<\/strong><\/p>\n<p><strong>3. Nested Classes<\/strong><\/p>\n<p><strong>4. Abstract classes<\/strong><\/p>\n<p><strong>5. Classes.<\/strong><\/p>\n<h3>Functional Interfaces in Java<\/h3>\n<p>Java 8 introduced the concept of functional interfaces. A functional interface is an interface that contains a single abstract method. This makes them ideal for use with lambda expressions, which are anonymous functions that can be passed as arguments to methods. Functional interfaces and lambda expressions together provide a powerful way to write concise and expressive code.<\/p>\n<h3>Summary<\/h3>\n<p>In this article, we learned about the basics of interfaces in Java, why they are useful, how to use interface variables and methods, and how it&#8217;s different from classes. We also came to know about the various similarities between classes and interfaces in Java. Interfaces are very popular in object-oriented development, and a good idea of the concept is essential for a software developer or a programmer in Java.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We have learned about interfaces in the article \u201cAbstraction in Java\u201d. In this article, we will take a deeper look at interfaces in Java. Let us look at a real-life example for interfaces. You&#46;&#46;&#46;<\/p>\n","protected":false},"author":5,"featured_media":84380,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[20970,20967,20965,20966,20969,20968],"class_list":["post-8106","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","tag-advantages-of-java-interface","tag-implementing-interface-in-java","tag-java-classes-vs-interface","tag-java-interface-tutorial","tag-java-interface-with-example-program","tag-use-of-interface-in-java"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Interface in Java - Explore Difference Between Classes and Interfaces - DataFlair<\/title>\n<meta name=\"description\" content=\"Interface in Java is similar to classes. Learn advantages, syntax, application and difference between Class and Interface with some examples.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/interface-in-java\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Interface in Java - Explore Difference Between Classes and Interfaces - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Interface in Java is similar to classes. Learn advantages, syntax, application and difference between Class and Interface with some examples.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/interface-in-java\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-02-15T08:57:59+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-05-18T11:13:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Interfaces-in-Java-df.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Interface in Java - Explore Difference Between Classes and Interfaces - DataFlair","description":"Interface in Java is similar to classes. Learn advantages, syntax, application and difference between Class and Interface with some examples.","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:\/\/data-flair.training\/blogs\/interface-in-java\/","og_locale":"en_US","og_type":"article","og_title":"Interface in Java - Explore Difference Between Classes and Interfaces - DataFlair","og_description":"Interface in Java is similar to classes. Learn advantages, syntax, application and difference between Class and Interface with some examples.","og_url":"https:\/\/data-flair.training\/blogs\/interface-in-java\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2018-02-15T08:57:59+00:00","article_modified_time":"2026-05-18T11:13:03+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Interfaces-in-Java-df.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/interface-in-java\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/interface-in-java\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823"},"headline":"Interface in Java &#8211; Explore Difference Between Classes and Interfaces","datePublished":"2018-02-15T08:57:59+00:00","dateModified":"2026-05-18T11:13:03+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/interface-in-java\/"},"wordCount":1774,"commentCount":3,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/interface-in-java\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Interfaces-in-Java-df.jpg","keywords":["Advantages of Java interface","Implementing Interface in Java","Java Classes Vs Interface","Java Interface tutorial","Java Interface with example program","Use of Interface in Java"],"articleSection":["Java Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/interface-in-java\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/interface-in-java\/","url":"https:\/\/data-flair.training\/blogs\/interface-in-java\/","name":"Interface in Java - Explore Difference Between Classes and Interfaces - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/interface-in-java\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/interface-in-java\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Interfaces-in-Java-df.jpg","datePublished":"2018-02-15T08:57:59+00:00","dateModified":"2026-05-18T11:13:03+00:00","description":"Interface in Java is similar to classes. Learn advantages, syntax, application and difference between Class and Interface with some examples.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/interface-in-java\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/interface-in-java\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/interface-in-java\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Interfaces-in-Java-df.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Interfaces-in-Java-df.jpg","width":1200,"height":628,"caption":"Interface in Java"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/interface-in-java\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Java Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/java\/"},{"@type":"ListItem","position":3,"name":"Interface in Java &#8211; Explore Difference Between Classes and Interfaces"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team creates expert-level guides on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our goal is to empower learners with easy-to-understand content. Explore our resources for career growth and practical learning.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam1\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/8106","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=8106"}],"version-history":[{"count":12,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/8106\/revisions"}],"predecessor-version":[{"id":148355,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/8106\/revisions\/148355"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/84380"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=8106"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=8106"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=8106"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}