What is the difference between Abstract and Interface?
Answers were Sorted based on User's Feedback
my name is skpotla.
the following answer is the exact one.
1.An abstract class is a class with zero or more abstract
methods.
2.Abstract class contains instance variables, concrete
methods in addition to abstract methods.
3.Both abstract class and abstract methods should be
declared as abstract.
4.We can not create and object to the abstract class.
5.We can create a reference to the abstract class type.
6.If you extends the abstract class in a sub class you have
to implement all the methods of the abstract class.
7.If u miss any abstract methods in the sub class then the
sub class should be declared as an abstract class.
8. A class can not be both abstract and final.
1.Interface is a specification of a method prototype.
2.Interface methods are by default abstract and public.
3.Interface contains variables which are by default
public,static and final.
4.Interface contains zero or more abstract methods.
5.We can not create an object to an interface.
6.We can create a reference to the interface type.
7.If we implement an interface we have to implement all its
methods in our sub class.
8. If any one miss then the class should be declared as an
abstract class.
9.Interface can not implements an other interface.
10.Interface can extends the other interface.
11.It is possible to write a class with in an interface.
Is This Answer Correct ? | 9 Yes | 0 No |
Answer / ram praswesh kumar
[1]:-> An abstract class contain abstract method and non-
abstract method, but In interface all method are implictly
abstract.
[2]:-> An abstract base class can have private,public and
protected access specifier but all member in interface are
implicitly public.
[3]:- A class can inherit only single abstract class but
can implement more than one interface.
[4]:- An abstract class can implement interface but
interface cannot extend abstract class even concrete class.
Is This Answer Correct ? | 10 Yes | 2 No |
Answer / rajesh kushwaha
• Abstract classes can have concrete methods while
interfaces have no methods implemented.
• Interfaces do not come in inheriting chain, while
abstract classes come in inheritance.
Is This Answer Correct ? | 15 Yes | 8 No |
Answer / code project main se teepa hai
An interface cannot provide any code, just the signature.
An abstract class can provide complete, default code and/or
just the details that have to be overridden.
Access Modfiers An interface cannot have access modifiers
for the subs, functions, properties etc everything is
assumed as public An abstract class can contain access
modifiers for the subs, functions, properties
Core VS Peripheral
Interfaces are used to define the peripheral abilities of a
class. In other words both Human and Vehicle can inherit
from a IMovable interface.
An abstract class defines the core identity of a class and
there it is used for objects of the same type.
Homogeneity
If various implementations only share method signatures then
it is better to use Interfaces.
If various implementations are of the same kind and use
common behaviour or status then abstract class is better to use.
Speed
Requires more time to find the actual method in the
corresponding classes.
Fast
Adding functionality (Versioning)
If we add a new method to an Interface then we have to track
down all the implementations of the interface and define
implementation for the new method.
If we add a new method to an abstract class then we have the
option of providing default implementation and therefore all
the existing code might work properly.
Fields and Constants No fields can be defined in
interfaces An abstract class can have fields and constrants
defined
Is This Answer Correct ? | 8 Yes | 1 No |
Answer / shiba shankar
1.In abstact class there may or may not have abstract
method.If there is one abstract method that must be a
abstract class.In interface the methods are bydefault
static and final.
2.Once we make abstract class means that's to be
extended.And the interface to be imlemented by making a
class.Through interface we can overcome the
multipleinheritance.
Is This Answer Correct ? | 17 Yes | 11 No |
Answer / nevin jain
-Abstract class contains both data members n members
functions.... but Interface contains only members functions
-Abstract class contains both complete n incomplete methods,
incomplete methods has to be explicitly marked as abstract
method...where as Interface contains all incomplete method n
no abstract keyword is requires explicitly.
-Abstract class n theirs members can be public,private or
protected whereas... By default access modifier are public n
no other access modifier can be given to interface n theirs
members.
-Abstract class members are inherit into derived class as
inherit members whereas... Interface members as inherited as
prototype members..
-Abstract class contain constructor whereas.. interface does
not contain..
Is This Answer Correct ? | 5 Yes | 0 No |
Answer / muhammad hussain wazir pakista
1: Abstract class contains abstract and non abstract methods
while interface contains all abstract methods.
2: Interface only contain definition of method no
implementation but Abstract class can have this quality.
3: We can not create object of abstract class.
4: We can create constructor and Destructure Abstract class
can while this can be do in Interface.
5: In interface all methods are abstract and have no keyword
of Abstract with method.
Is This Answer Correct ? | 5 Yes | 2 No |
Answer / jithin j
Interface: contain only abstract method and static and final (constant) variable.Even if we don't use static and final keyword it is considered as constant
Abstract: contain both abstract and non abstract method
Interface: class implements interface
Abstract : class extends abstract class
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / ntmohare
Abstract Class:
(1)it contains both abstract methods and non abstract methods
(2) object can't be created just through reference we are calling all the methods
(3) it is implemented by subclass i.e which class is extended from this
abstract class contains only nonabstract this situation also code will compile fine but problem at runtime
abstract can't be declared with Final Synchronized Native just your requirements you implement some methods in the abstract class
this class also contain Constructor
========
Interface contains all abstract methods
all methods compulsory implemented by particular class
interface does not contain Constructor
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / thulasiram
interface can have only non implementation methods
abstract class can have both implementation and non
implementation methods
interfaces are used for universal access
Is This Answer Correct ? | 0 Yes | 0 No |
What is ulong in c#?
How long does it take to learn c# for unity?
Explain how do you convert a value-type to a reference-type?
What are the boolean data types in c#?
Does c# support try-catch-finally blocks?
What is the root element of an xml file?
What is the partial class in C# What is the use of partial class in C#?
what are advantages and disadvantages of Microsoft-provided data provider classes in ADO.NET?
What are c# collections?
What is the difference between new and override in c#?
Do extension methods have to be static?
What are delegate methods?