Interfaces are essentially having all method prototypes no definition but Abstract class can contain method definations also.
In short Interface is a abstract class having all methods abstract.
Both abstract classes and interfaces are used when there is a difference in behaviour among the sub-types extending the abstract class or implementing the interface.
When the sub-types behaviour is totally different then you use an interface, when the sub-types behaviour is partially common and different with respect to the supertype an abstract class is used. In an abstract class the partially common behaviour is given a concrete implementation. Since there is no common behaviour between an interface and a sub-type an interface does not have an implementation for any of its behaviour.
If you create a abstract class writing the abstract keyword in the declaration part then You only can inherit the class. You can not create an instance of this abstract class but can inherit the class and with creating the instance of the derived class you can access the method of the abstract class.
If you use a virtual keyword in a method then you can override this method in the subclass if you wish..
If you create a abstract method then you must override this method in the subclass other wise it shows error in the program.
The concentration moved away from Interface towards Abstract Class. Better provide some examples… those would add extra values to the explanation.
interface also have signature or definition.
interface is fully abstract.means interface only and only contain the declaration of the methods,but definition implemented in the class.
Short but hitting bulls eye…
Good Post. Must read to get the Laymen Definition of the Interface and Abstract Class. A piece of code would make the post much much better.
Good for beginners and graduate students like me.
Hi mam
This is the best post on Abstract class and interface that i ever read on the net. very good effort….
Oh please… that’s just retarded. Do you even know how to use google? Derp!
hello
sorry my friend is making fun of me.
this is a good post
a very nice articel
its very good article……..
better u people provide examples….Explanation along with examples will always be better.
My confusion about abstract vs interface goes away once and for all with this article.
Good Job and thanks a lot.
Short and fine…….for first steppers
hi
Momin Ashfaque :
Hi,
I am very confused in abstract class and interface in c#.net ,so if any good example or idea about that topic so send on my e-mail.
An abstract class can have abstract members as well non abstract members. But in an interface all the members are implicitly abstract and all the members of the interface must override to its derived class.
{
//All methods are automaticall abstract
int AddNumbers(int Num1, int Num2);
int MultiplyNumbers(int Num1, int Num2);
}
Defining an abstract class with abstract members has the same effect to defining an interface.
The members of the interface are public with no implementation. Abstract classes can have protected parts, static methods, etc.
A class can inherit one or more interfaces, but only one abstract class.
Abstract classes can add more functionality without destroying the child classes that were using the old version. In an interface, creation of additional functions will have an effect on its child classes, due to the necessary implementation of interface methods to classes.
The selection of interface or abstract class depends on the need and design of your project. You can make an abstract class, interface or combination of both depending on your needs.
ok thanks
but i am having one doubt where we use in real time both this
nice
Good but always mention examples then the programming language can easily understand
Abstract is better then interface .. Interface do not have static method too
Nice post. really like it
ITS NICE.. BUT INTERFACE & ABSTRACT CLASS YOU HAVE TO EXPLAIN WITH EXAMPLES.. THEN ONLY DIFFERENCES IS EXPLAIN BRIEFLY.
interface class cannot implement Method only declare signature. ans support for multiple inheritance ,not use abstract or override the method
Abstract class both have type method ,but abustruct method only give the definition not implement.but other methods is your choice
Very nice post.
It clears all my concepts related to Abstract class and interfaces.
God Bless u..
Abstract class atleast one method is unified.
interface all method is unified
hello
Very nice post.
It clears all my concepts related to Abstract class and interfaces.
All the Best
very nice.it clear my doubts.superb….
gud but one example makes it perfec……..understanding