+ 17

Difference between interface and abstact class?

4th May 2017, 12:50 PM
Bilal Naeem
Bilal Naeem - avatar
36 Réponses
+ 31
Interface: - Contains no concrete implementation of a method - a subclass can implement (theoretically) an infinite amount of interfaces - Interfaces are faster than abstract classes Abstract class: - Can contain concrete implementation of a method - a subclass can only implement one super-class
4th May 2017, 1:04 PM
Thanh Le
Thanh Le - avatar
+ 13
abstract class can have concrete methods
9th May 2017, 9:55 PM
NimWing Yuan
NimWing Yuan - avatar
+ 4
Adding to @Thanh Le, in the C++ interfaces are implemented using abstract classes.
4th May 2017, 1:22 PM
देवेंद्र महाजन (Devender)
देवेंद्र महाजन (Devender) - avatar
+ 4
The main difference between them is that a class can implement more than one interface but can only inherit from one abstract class. Since C# doesn't support multiple inheritance, interfaces are used to implement multiple inheritance. i hope it will help u..:-)
4th May 2017, 4:01 PM
Vishal Sakariya
Vishal Sakariya - avatar
+ 4
Java interfaces are implicitly abstract and they actually act as a reference to abstract class and what variable they have they are by default final they can only implement from other interfaces but in abstract class u can inherit it with other Java classes and their members can be public private and protected
7th May 2017, 5:40 AM
prakhar dixit
prakhar dixit - avatar
+ 4
in generally you have permission to implement method in abstract but not in an interface.
9th May 2017, 5:39 PM
Hamid Jolany
Hamid Jolany - avatar
+ 3
I'd like to think of interfaces as an extreme form of abstract classes where all methods are abstract, but for abstract classes, you can have non-abstract methods.
4th May 2017, 1:45 PM
Sammi
Sammi - avatar
+ 3
Main difference is methods of a Java interface are implicitly abstract and cannot have implementations. A Java abstract class can have instance methods that implements a default behavior. Variables declared in a Java interface is by default final. An abstract class may contain non-final variables.
5th May 2017, 3:59 PM
P∆WAN M∆URY∆
P∆WAN M∆URY∆ - avatar
+ 3
Please mark best answer the most helpful answer so people will see it on the top
15th May 2017, 11:19 AM
Shahar Levy
Shahar Levy - avatar
+ 3
First step is:- abstract class may contents implementation or may not contents implementation but object creation is not allows... abstract class Test { void m1() { cout<<"m1 method";//m1 method empliment } void m2()//m2 method implement { cout<<"m2 method"; } abstract void m3();//m3 method not implemented } second step:- you can create object in another class with extends keyword ------------------------------------------------------------------------------------------- interace is pure abstract class. means you just declear methods but object creation is not allowed interface Test { void m1();//just m1 method decleared void m2();//just m2 method decleared void m3();//just m3 method decleared } now you should create a object to another class with implement keyword... ------------------------------------------------------------------------------------------- my english is not good and i'm not properly talking about abstract and interfaces because in front of this website not providing video....
21st May 2017, 7:44 PM
meherDev
meherDev - avatar
+ 3
Structural Difference: abstract class can contain empty methods as well as standard methods i.e non-empty method. on the other hand interface contains only empty methods. Usage Difference: if you want that, a child class inherited from a parent class that must implement all the methods defined in the parent class then its better to use "interface", and if you don't want so, then use " abstract class ".
22nd May 2017, 12:09 PM
Kartick Bhowmik
Kartick Bhowmik - avatar
+ 2
thanx to all
4th May 2017, 8:35 PM
Bilal Naeem
Bilal Naeem - avatar
+ 2
I dont know
8th May 2017, 9:56 AM
TONMOY SANTRA
TONMOY SANTRA - avatar
+ 2
if everything is abstract in an abstract class then what will be the difference between interface and abstract class ???
8th May 2017, 3:05 PM
Elsa
Elsa - avatar
+ 2
Actually interfaces in Java (at least in version 8) can also have concrete methods through "default" methods.
11th May 2017, 9:04 AM
Eliezer Benjamin
+ 2
Abstract Classes Compared to Interfaces Abstract classes are similar to interfaces. You cannot instantiate them, and they may contain a mix of methods declared with or without an implementation. However, with abstract classes, you can declare fields that are not static and final, and define public, protected, and private concrete methods. With interfaces, all fields are automatically public, static, and final, and all methods that you declare or define (as default methods) are public. In addition, you can extend only one class, whether or not it is abstract, whereas you can implement any number of interfaces. Taken from: https://docs.oracle.com/javase/tutorial/java/IandI/abstract.html
13th May 2017, 6:49 PM
Eliezer Benjamin
+ 2
abstract class is a class which may or may not have a abstract method. But interface contains all abstract methods(unimplemented methods).
22nd May 2017, 6:01 AM
Pavan Muniganti
Pavan Muniganti - avatar
+ 1
tonmoy I am saying we can add static methods to interface
8th May 2017, 10:15 AM
Ashutosh Chopde
Ashutosh Chopde - avatar
+ 1
it is a sub class can only implement one superclass
11th May 2017, 10:20 AM
mahima
+ 1
Interface support multiple inheritance. Member of interface cannot be static. Interface doesn't contains constructor. Abstract class cannot support multiple inheritance. Member of abstract class always static. Abstract class support constructor.
12th May 2017, 7:49 AM
Sonam
Sonam - avatar