

{"id":9283,"date":"2018-02-24T10:00:09","date_gmt":"2018-02-24T10:00:09","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=9283"},"modified":"2026-05-30T15:54:02","modified_gmt":"2026-05-30T10:24:02","slug":"difference-between-abstract-class-and-interface-in-java","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/difference-between-abstract-class-and-interface-in-java\/","title":{"rendered":"Difference Between Abstract Class and Interface in Java"},"content":{"rendered":"<p>Hey there! So someone asked you the Difference between Abstract Class and Interface in Java and you ended up searching for it on Google? And maybe other articles did not really make you understand the topic. This question is a very popular question in interviews. There are high chances that you will be asked this one if you are applying for a Java developer role in a company.<\/p>\n<p>So let us start with the differences between the two concepts!<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Difference-between-Abstract-Classes-and-Interfaces.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-84502 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Difference-between-Abstract-Classes-and-Interfaces.jpg\" alt=\"Difference between Abstract Class and Interface in java\" width=\"1200\" height=\"628\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Difference-between-Abstract-Classes-and-Interfaces.jpg 1200w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Difference-between-Abstract-Classes-and-Interfaces-300x157.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Difference-between-Abstract-Classes-and-Interfaces-1024x536.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Difference-between-Abstract-Classes-and-Interfaces-150x79.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Difference-between-Abstract-Classes-and-Interfaces-768x402.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Difference-between-Abstract-Classes-and-Interfaces-720x377.jpg 720w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Difference-between-Abstract-Classes-and-Interfaces-520x272.jpg 520w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Difference-between-Abstract-Classes-and-Interfaces-320x167.jpg 320w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/a><\/p>\n<h3>Abstract Classes in Java<\/h3>\n<p>Abstract methods, in Java, are those methods which only contain the prototype of the function and lack the body. This means that only the function name, access specifier, return type, and the parameters are known to the method itself. The method does not have a body.<\/p>\n<p>If there are abstract methods in a class in Java, then the class also must be an abstract class.<\/p>\n<p>A very simple example of an abstract class would be<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">abstract class AbstractClassName\/\/this is the abstract class. \r\n{\r\n    abstract public void abstractMethodName();\/\/This is the abstract method. \r\n}\r\n\r\n<\/pre>\n<p>As you can see the abstractMethodName does not have a body. This type of method is an abstract method. However, it is not necessary for a class that is abstract to only contain abstract methods. An abstract class can house concrete methods as well!<\/p>\n<p>Let us check out a brief program on abstract classes to refresh our memory of what they are like.<\/p>\n<p><strong>Program to illustrate the use of Abstract Classes in Java<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">package com.dataflair.abstractvsinterface;\r\nabstract class AbstractClass\r\n{\r\n    abstract void methodabs();\r\n}\r\npublic class Main extends AbstractClass\r\n{\r\n    public void methodabs()\r\n    {\r\n        System.out.println(\"We defined this inside the Main class. \");\r\n        \r\n    }\r\n    public static void main(String[] args) {\r\n        Main ob = new Main();\r\n        ob.methodabs();\r\n        \r\n    }\r\n}\r\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">We defined this inside the Main class.<\/div>\n<h3>Interfaces in Java<\/h3>\n<p>Interfaces are somewhat similar to abstract classes. They contain method prototypes that a class implements. If this is entirely new to you, check out our article on interfaces. Interfaces allow us to implement multiple interfaces in Java.<\/p>\n<p><strong>Program to illustrate the use of interfaces in Java:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">package com.dataflair.abstractvsinterface;\r\ninterface CustomInterface\r\n{\r\n    public void methodabs();\r\n}\r\npublic class Main implements CustomInterface\r\n{\r\n    \/\/Now we will implement the method of the interface here. \r\n    public void methodabs()\r\n    {\r\n        System.out.println(\"We defined the definition of the interface method here.\");\r\n        \r\n    }\r\n    public static void main(String[] args) {\r\n        Main ob = new Main();\r\n        ob.methodabs();\r\n        \r\n    }\r\n}\r\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">We defined the definition of the interface method here.<\/div>\n<p>Note how the class implements the methods in the interface. Now that we are familiar, let us get to know the differences between these concepts.<\/p>\n<h3>Key Differences Between Abstract Class and Interface in Java<\/h3>\n<table>\n<tbody>\n<tr>\n<td><b>Parameters<\/b><\/td>\n<td><b>Interfaces in Java<\/b><\/td>\n<td><b>Abstract Classes in Java<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Speed<\/span><\/td>\n<td><span style=\"font-weight: 400\">Interfaces are slow.\u00a0<\/span><\/td>\n<td><span style=\"font-weight: 400\">Abstract Classes are fast.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Multiple Inheritance<\/span><\/td>\n<td><span style=\"font-weight: 400\">Interface can implement several interfaces.<\/span><\/td>\n<td><span style=\"font-weight: 400\">Abstract classes can extend only one class.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Structure<\/span><\/td>\n<td><span style=\"font-weight: 400\">Can contain only abstract, default, and static methods.\u00a0<\/span><\/td>\n<td><span style=\"font-weight: 400\">There can be abstract as well as concrete methods inside an abstract class.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Used for<\/span><\/td>\n<td><span style=\"font-weight: 400\">Interfaces are useful for future enhancement.<\/span><\/td>\n<td><span style=\"font-weight: 400\">Abstract classes generally are useful to avoid independence.\u00a0\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Default Implementation<\/span><\/td>\n<td><span style=\"font-weight: 400\">Before the advent of Java 8 it was very difficult to add a new abstract method in an interface. But now an interface can have default methods too.\u00a0<\/span><\/td>\n<td><span style=\"font-weight: 400\">Abstract classes can have default methods.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Access Modifier<\/span><\/td>\n<td><span style=\"font-weight: 400\">Any method or variable inside an interface is public by default.\u00a0<\/span><\/td>\n<td><span style=\"font-weight: 400\">An abstract class can have private and protected methods inside it.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">When to use<\/span><\/td>\n<td><span style=\"font-weight: 400\">If different implementations share the same method signature, interfaces are useful.\u00a0<\/span><\/td>\n<td><span style=\"font-weight: 400\">Abstract classes are useful when implementations have common behavior.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Access Modifier usage<\/span><\/td>\n<td><span style=\"font-weight: 400\">You cannot use access modifiers in an interface for its methods.\u00a0<\/span><\/td>\n<td><span style=\"font-weight: 400\">An abstract class allows you to set access modifiers to its methods and data.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Usefulness<\/span><\/td>\n<td><span style=\"font-weight: 400\">When you need to define the peripheral abilities of a class, interfaces can be very useful.\u00a0<\/span><\/td>\n<td><span style=\"font-weight: 400\">Abstract classes are generally used for defining the identity of the class.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Defined Fields<\/span><\/td>\n<td><span style=\"font-weight: 400\">You cannot define fields in an interface<\/span><\/td>\n<td><span style=\"font-weight: 400\">In abstract classes, you can define fields as well as constants.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Constructors and Destructors<\/span><\/td>\n<td><span style=\"font-weight: 400\">As interfaces are not classes, they cannot have constructors or destructors.\u00a0<\/span><\/td>\n<td><span style=\"font-weight: 400\">On the other hand, abstract classes can have constructors and destructors.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Abstract Keyword<\/span><\/td>\n<td><span style=\"font-weight: 400\">Interfaces do not need an abstract keyword for declaring its methods as abstract.<\/span><\/td>\n<td><span style=\"font-weight: 400\">All methods inside an abstract class must have the abstract keyword.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Class Type<\/span><\/td>\n<td><span style=\"font-weight: 400\">Interfaces can house public methods only.\u00a0<\/span><\/td>\n<td><span style=\"font-weight: 400\">Abstract classes can house private and protected abstract methods as well.\u00a0<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Programs to Illustrate Differences Between Abstract Classes and Interfaces in Java<\/h3>\n<p><strong>You can extend only one abstract class or a concrete class from an abstract class at a time.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">package com.dataflair.abstractvsinterface;\r\nclass ConcreteClassOne{\r\n   public void method1(){\r\n      System.out.println(\"This is method 1\");\r\n   }\r\n}\r\nabstract class AbstractClassOne{\r\n   public void display2(){\r\n      System.out.println(\"This is method 2\");\r\n   }\r\n}\r\nabstract class AbstractClassTwo extends ConcreteClassOne{\r\n   abstract void display3();\r\n}\r\nclass ConcreteClassFour extends AbstractClassTwo{\r\n   public void display3(){\r\n      System.out.println(\"This is method 3\");\r\n   }\r\n}\r\npublic class Demo\r\n{\r\n    public static void main(String[] args) {\r\n        ConcreteClassFour object = new ConcreteClassFour();\r\n        object.display3();\r\n    }\r\n}\r\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">This is method 3<\/div>\n<p><strong>A single interface can extend more than one interface at a time.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">package com.dataflair.abstractvsinterface;\r\ninterface InterfaceOne\r\n{\r\n    public void abstractMethodOne();\r\n}\r\ninterface InterfaceTwo\r\n{\r\n    public void abstractMethodTwo();\r\n\r\n}\r\ninterface InterfaceThree extends InterfaceOne,InterfaceTwo\r\n{\r\n    \/\/This interface inherits more than one interface\r\n}\r\n\r\npublic class InterfaceDifference1 implements InterfaceThree {\r\n    public void abstractMethodOne()\r\n    {\r\n        System.out.println(\"This is the first abstract method from the first interface\");\r\n\r\n    }\r\n    public void abstractMethodTwo()\r\n    {\r\n        System.out.println(\"This is the second abstract method from the second interface\");\r\n    }\r\n    public static void main(String[] args) {\r\n        InterfaceDifference1 object = new InterfaceDifference1();\r\n        object.abstractMethodOne();\r\n        object.abstractMethodTwo();\r\n    }\r\n    \r\n}\r\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">This is the first abstract method from the first interface<br \/>\nThis is the second abstract method from the second interface<\/div>\n<p><strong>A single abstract class or a concrete class can inherit an abstract class.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">package com.dataflair.abstractvsinterface;\r\nclass ConcreteClassOne\r\n{\r\n    public void concreteMethod()\r\n    {\r\n        System.out.println(\"This is a concrete method\");\r\n    }\r\n}\r\nabstract class AbstractClass extends ConcreteClassOne\r\n{\r\n    abstract public void abstractMethodOne();\r\n}\r\n\r\npublic class AbstractClassDifference2 extends AbstractClass {\r\n    public void abstractMethodOne()\r\n    {\r\n        System.out.println(\"This is the Abstract method\");\r\n    }\r\n    public static void main(String[] args) {\r\n        AbstractClassDifference2 object = new AbstractClassDifference2();\r\n        object.abstractMethodOne();\r\n        object.concreteMethod();\r\n    }\r\n    \r\n}\r\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">This is the Abstract method<br \/>\nThis is a concrete method<\/div>\n<p><strong>Interfaces can only extend other interfaces. A class has to implement interfaces.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">package com.dataflair.abstractvsinterface;\r\ninterface InterfaceOne\r\n{\r\n    public void abstractMethod1();\r\n}\r\ninterface InterfaceTwo extends InterfaceOne\r\n{\r\n    \/\/Empty Interface\r\n}\r\n\r\npublic class InterfaceDifference2 implements InterfaceTwo{\r\n    public void abstractMethod1()\r\n    {\r\n        System.out.println(\"This is the abstract method\");\r\n    }\r\n    public static void main(String[] args) {\r\n        InterfaceDifference2 object = new InterfaceDifference2();\r\n        object.abstractMethod1();\r\n    }\r\n    \r\n}\r\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">This is the abstract method<\/div>\n<p><strong>Abstract classes can contain abstract and concrete methods.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">package com.dataflair.abstractvsinterface;\r\nabstract class AbstractClassOne\r\n{\r\n    public void concreteMethod1()\r\n    {\r\n        System.out.println(\"This is a concrete method\");\r\n\r\n    }\r\n    abstract void abstractMethod1();\r\n}\r\n\r\n\r\npublic class AbstractClassDifference3 extends AbstractClassOne {\r\n    public void abstractMethod1()\r\n    {\r\n        System.out.println(\"This is an abstract method\");\r\n    }\r\n    public static void main(String[] args) {\r\n        AbstractClassDifference3 object = new AbstractClassDifference3();\r\n        object.concreteMethod1();\r\n        object.abstractMethod1();\r\n    }\r\n}\r\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">This is a concrete method<br \/>\nThis is an abstract method<\/div>\n<p><strong>Interfaces can only have static, default, and abstract methods.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">package com.dataflair.abstractvsinterface;\r\ninterface InterfaceNumber1\r\n{\r\n    public void abstractMethod1();\r\n}\r\n\r\npublic class InterfaceDifference3 implements InterfaceNumber1{\r\n    \r\n    public void abstractMethod1()\r\n    {\r\n        System.out.println(\"This is the abstract method. An interface can also have default and static methods\");\r\n\r\n    }\r\n    public static void main(String[] args) {\r\n        InterfaceDifference3 object = new InterfaceDifference3();\r\n        object.abstractMethod1();\r\n    }\r\n}\r\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">This is the abstract method. An interface can also have default and static methods<\/div>\n<p><strong>An abstract keyword is mandatory for declaring an abstract method in abstract classes.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">package com.dataflair.abstractvsinterface;\r\nabstract class AbstractClassOne\r\n{\r\n    abstract public void abstractMethod1();\r\n}\r\n\r\n\r\npublic class AbstractClassDifference4 extends AbstractClassOne{\r\n    public void abstractMethod1()\r\n    {\r\n        System.out.println(\"This is the abstract method. It is compulsory to use the abstract keyword\");\r\n    }\r\n    public static void main(String[] args) \r\n    {\r\n        AbstractClassDifference4 object = new AbstractClassDifference4();\r\n        object.abstractMethod1();\r\n    }\r\n    \r\n}\r\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">This is the abstract method. It is compulsory to use the abstract keyword<\/div>\n<p><strong>An interface does not require abstract keyword to declare its methods as abstract.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">package com.dataflair.abstractvsinterface;\r\ninterface InterfaceOne\r\n{\r\n    abstract public void methodOne();\r\n    public void methodTwo();\r\n}\r\n\r\n\r\npublic class InterfaceDifference4 implements InterfaceOne{\r\n    public void methodOne()\r\n    {\r\n        System.out.println(\"This method is abstract with the help of abstract keyword\");\r\n    }\r\n    public void methodTwo()\r\n    {\r\n        System.out.println(\"This is an abstract method even without the help of abstract keyword\");\r\n    }\r\n    public static void main(String[] args) \r\n    {\r\n     \r\n    InterfaceDifference4 object = new InterfaceDifference4();\r\n    object.methodOne();\r\n    object.methodTwo();   \r\n    }\r\n\r\n}\r\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">This method is abstract with the help of abstract keyword<br \/>\nThis is an abstract method even without the help of abstract keyword<\/div>\n<p><strong>You can have protected and public abstract methods inside an abstract class.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">package com.dataflair.abstractvsinterface;\r\nabstract class AbstractClassOne\r\n{\r\n    abstract public void methodPublic();\r\n    abstract protected void methodProtected();\r\n\r\n}\r\npublic class AbstractClassDifference5 extends AbstractClassOne\r\n{\r\n    public void methodPublic()\r\n    {\r\n        System.out.println(\"This is a public method\");\r\n    }\r\n    public void methodProtected()\r\n    {\r\n        System.out.println(\"This is a protected method\");\r\n    }\r\n    public static void main(String[] args) \r\n    {\r\n        AbstractClassDifference5 object = new AbstractClassDifference5();\r\n        object.methodPublic();\r\n        object.methodProtected();\r\n    }\r\n    \r\n}\r\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">This is a public method<br \/>\nThis is a protected method<\/div>\n<p><strong>There can only be public abstract methods inside interfaces.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">package com.dataflair.abstractvsinterface;\r\ninterface InterfaceOne\r\n{\r\n    public void methodOne();\r\n}\r\n\r\npublic class InterfaceDifference5 implements InterfaceOne\r\n{\r\n    public void methodOne()\r\n    {\r\n        System.out.println(\"Interfaces can only have public abstract methods\");\r\n\r\n    }\r\n    public static void main(String[] args) {\r\n        InterfaceDifference5 object = new InterfaceDifference5();\r\n        object.methodOne();\r\n    }\r\n    \r\n}\r\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Interfaces can only have public abstract methods<\/div>\n<p><strong>An abstract class can have static, final or static final variables.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">package com.dataflair.abstractvsinterface;\r\nabstract class AbstractClassOne\r\n{\r\n    protected final int protecVar=50;\r\n    public void printValue()\r\n    {\r\n        System.out.println(\"The protected Value is \"+protecVar);\r\n    }\r\n\r\n}\r\n\r\npublic class AbstractClassDifference6 extends AbstractClassOne{\r\n    public static void main(String[] args) {\r\n     AbstractClassOne object = new AbstractClassDifference6();\r\n     object.printValue();   \r\n    }\r\n    \r\n}\r\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">The protected value is 50<\/div>\n<p><strong>Interfaces can only contain public static final variables.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">package com.dataflair.abstractvsinterface;\r\ninterface InterfaceOne\r\n{\r\n    \/\/They can have public static variables\r\n    int publicStaticVar=50;\r\n}\r\n\r\npublic class InterfaceExample6 implements InterfaceOne {\r\n    public void readvalue()\r\n    {\r\n        System.out.println(\"The value of the variable is \"+publicStaticVar);\r\n    }\r\n    public static void main(String[] args) {\r\n        InterfaceExample6 object = new InterfaceExample6();\r\n        object.readvalue();\r\n    }\r\n    \r\n}\r\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">The value of the variable is 50<\/div>\n<h3>Reasons to use Abstract Classes in Java<\/h3>\n<ul>\n<li>You can offer default functionality with the help of abstract classes.<\/li>\n<li>You can specify a particular template for future specific classes.<\/li>\n<li>Abstract classes allow you to reuse code.<\/li>\n<li>With the help of abstract classes you can define a common interface for your subclasses.<\/li>\n<li>Abstract class helps in providing safety to the program by having a limited access of the members.<\/li>\n<li>It is useful when the state of the object is changing. The objects and methods inside the abstract class cannot be declared as static or final.<\/li>\n<\/ul>\n<h3>Reasons to use Interfaces in Java<\/h3>\n<ul>\n<li>You can achieve 100% abstraction with the help of interfaces in Java<\/li>\n<li>You can resolve methods dynamically at runtime with the help of interfaces.<\/li>\n<li>You can separate the definition of a method from its inheritance hierarchy with the help of interfaces.<\/li>\n<li>You can also achieve loose coupling with the help of interfaces.<\/li>\n<li>Java lacks in achieving multiple inheritance but by using interfaces it can be implemented.<\/li>\n<\/ul>\n<h3>When should you use Java Interfaces?<\/h3>\n<p>You should use interfaces when:<\/p>\n<ul>\n<li>You want 100 percent abstraction<\/li>\n<li>You want to implement multiple inheritance in Java<\/li>\n<li>You are more concerned with the behavior of the class rather than who is implementing the behavior.<\/li>\n<li>You want a child class to implement all abstract methods in the interface.<\/li>\n<\/ul>\n<h3>When should you use Java Abstract Classes?<\/h3>\n<p>You should use abstract classes when:<\/p>\n<ul>\n<li>Your application has some code that needs to be shared amongst different classes. An abstract class would contain all the abstract methods. The child classes can redefine each of these abstract methods separately.<\/li>\n<li>There is a need to use non-static and non-final values inside a class so that an object can modify these variables.<\/li>\n<li>You need to have private or protected methods and variables. Abstract Classes can be useful for containing protected and private methods as well as variables.<\/li>\n<\/ul>\n<h3>Summary<\/h3>\n<p>In this article, we primarily learned about the prime differences between abstract classes and interfaces in Java. We also learned about their uses, and when to use which in programming. Strong knowledge of these concepts would aid in the better development of software.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey there! So someone asked you the Difference between Abstract Class and Interface in Java and you ended up searching for it on Google? And maybe other articles did not really make you understand&#46;&#46;&#46;<\/p>\n","protected":false},"author":5,"featured_media":84502,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[196,199,3813,3854,6877],"class_list":["post-9283","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","tag-abstract-class-in-java","tag-abstract-class-vs-interface-in-java","tag-difference-between-abstract-class-and-interface-in-java","tag-difference-between-interface-vs-abstract-class-in-java","tag-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>Difference Between Abstract Class and Interface in Java - DataFlair<\/title>\n<meta name=\"description\" content=\"Difference between Abstract Class and Interface in Java with real time examples - What is Abstract Class vs Interface in Java and their uses.\" \/>\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\/difference-between-abstract-class-and-interface-in-java\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Difference Between Abstract Class and Interface in Java - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Difference between Abstract Class and Interface in Java with real time examples - What is Abstract Class vs Interface in Java and their uses.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/difference-between-abstract-class-and-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-24T10:00:09+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-05-30T10:24:02+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Difference-between-Abstract-Classes-and-Interfaces.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=\"6 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Difference Between Abstract Class and Interface in Java - DataFlair","description":"Difference between Abstract Class and Interface in Java with real time examples - What is Abstract Class vs Interface in Java and their uses.","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\/difference-between-abstract-class-and-interface-in-java\/","og_locale":"en_US","og_type":"article","og_title":"Difference Between Abstract Class and Interface in Java - DataFlair","og_description":"Difference between Abstract Class and Interface in Java with real time examples - What is Abstract Class vs Interface in Java and their uses.","og_url":"https:\/\/data-flair.training\/blogs\/difference-between-abstract-class-and-interface-in-java\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2018-02-24T10:00:09+00:00","article_modified_time":"2026-05-30T10:24:02+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Difference-between-Abstract-Classes-and-Interfaces.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":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/difference-between-abstract-class-and-interface-in-java\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/difference-between-abstract-class-and-interface-in-java\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823"},"headline":"Difference Between Abstract Class and Interface in Java","datePublished":"2018-02-24T10:00:09+00:00","dateModified":"2026-05-30T10:24:02+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/difference-between-abstract-class-and-interface-in-java\/"},"wordCount":1275,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/difference-between-abstract-class-and-interface-in-java\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Difference-between-Abstract-Classes-and-Interfaces.jpg","keywords":["Abstract Class in Java","Abstract Class vs Interface in Java","Difference between Abstract Class and Interface in Java","Difference between Interface vs Abstract Class in Java","Interface in Java"],"articleSection":["Java Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/difference-between-abstract-class-and-interface-in-java\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/difference-between-abstract-class-and-interface-in-java\/","url":"https:\/\/data-flair.training\/blogs\/difference-between-abstract-class-and-interface-in-java\/","name":"Difference Between Abstract Class and Interface in Java - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/difference-between-abstract-class-and-interface-in-java\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/difference-between-abstract-class-and-interface-in-java\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Difference-between-Abstract-Classes-and-Interfaces.jpg","datePublished":"2018-02-24T10:00:09+00:00","dateModified":"2026-05-30T10:24:02+00:00","description":"Difference between Abstract Class and Interface in Java with real time examples - What is Abstract Class vs Interface in Java and their uses.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/difference-between-abstract-class-and-interface-in-java\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/difference-between-abstract-class-and-interface-in-java\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/difference-between-abstract-class-and-interface-in-java\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Difference-between-Abstract-Classes-and-Interfaces.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Difference-between-Abstract-Classes-and-Interfaces.jpg","width":1200,"height":628,"caption":"Difference between Abstract Classes and Interfaces"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/difference-between-abstract-class-and-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":"Difference Between Abstract Class and Interface in Java"}]},{"@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\/9283","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=9283"}],"version-history":[{"count":9,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/9283\/revisions"}],"predecessor-version":[{"id":148526,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/9283\/revisions\/148526"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/84502"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=9283"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=9283"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=9283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}