What is the difference between Abstract and Interface?

Answers were Sorted based on User's Feedback



What is the difference between Abstract and Interface?..

Answer / skpotla

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

What is the difference between Abstract and Interface?..

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

What is the difference between Abstract and Interface?..

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

What is the difference between Abstract and Interface?..

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

What is the difference between Abstract and Interface?..

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

What is the difference between Abstract and Interface?..

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

What is the difference between Abstract and Interface?..

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

What is the difference between Abstract and Interface?..

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

What is the difference between Abstract and Interface?..

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

What is the difference between Abstract and Interface?..

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

Post New Answer

More C Sharp Interview Questions

Can an Assembly have multiple versions

13 Answers   TCS,


Explain the difference between class and interface in .net?

0 Answers  


Why var is used in c#?

0 Answers  


What is difference between virtual and override in c#?

0 Answers  


i have a table named login in mysql database containing (empid,fname,lname,mobno,emailid,usrname,usrpwd) i have 2 textboxes in which i enter my username and pwd..so based on what is entered in those textboxes it should retreive all other details of dat username in the remaining 6 textboxes..i want the code for this...

1 Answers   Royal Enfield,






What is value c#?

0 Answers  


Are structs value types or reference types?

0 Answers  


What is .net console?

0 Answers  


What are types in c#?

0 Answers  


What?s the difference between System.String and System.StringBuilder classes?

3 Answers  


Why use “using” in c#?

0 Answers  


What is the difference between cookies and session?

7 Answers   ADITI, Infinity, Infotech, VBV, Web Connect,


Categories