+ 17
Difference between interface and abstact class?
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
+ 13
abstract class can have concrete methods
+ 4
Adding to @Thanh Le, in the C++ interfaces are implemented using abstract classes.
+ 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..:-)
+ 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
+ 4
in generally you have permission to implement method in abstract but not in an interface.
+ 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.
+ 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.
+ 3
Please mark best answer the most helpful answer so people will see it on the top
+ 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....
+ 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 ".
+ 2
thanx to all
+ 2
I dont know
+ 2
if everything is abstract in an abstract class then what will be the difference between interface and abstract class ???
+ 2
Actually interfaces in Java (at least in version 8) can also have concrete methods through "default" methods.
+ 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
+ 2
abstract class is a class which may or may not have a abstract method.
But interface contains all abstract methods(unimplemented methods).
+ 1
tonmoy I am saying we can add static methods to interface
+ 1
it is a sub class can only implement one superclass
+ 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.