Difference between abstract class and interface

Answers were Sorted based on User's Feedback



Difference between abstract class and interface..

Answer / anwar .s

Abstract class:
.class inherites one class at time
(eg)class A extends B
.if we need two class two properties.Abstract class is not
possible.becoz it doesn't support multiple inheritance
(eg)class A extendssB,c->not possible.
.we cannot create object for abstract class.it doesn't
occupy memory
.it gives structure to program
.we cannot inherits properties to Abstract class.but we can
inherits all the properties from abstarct class.
.Abstract class have atleast one Abstract method
Interface:
.interface is nothing but u give structure for project will
be created on our desire
(eg) u give plan of house to buit.u told that i want this
model house.similiar to that programmer developed the
project according to ur plan they develop the code.they cant
change ur plan bcoz all are abstract
.by using interface multiple inhertance is possible
.(eg)interface implements classA,B,c...n
.interface is bodyless.
.the variable decalared inside the interface act as final
variable.we cannot re assign
(eg)final int a=10
int a=15 it shows error while compiling.

Is This Answer Correct ?    0 Yes 1 No

Difference between abstract class and interface..

Answer / aloka

INTERFACE:
1)a class can implement any number of interfaces.
2)variables declared in interfaces are by default final
3)members on interfaces are public by default
4)should be implemented using keyword "implements"
5)absolutely abstract and cannot be instantiated.
6)requires more time to find the actual method in the
corresponding class
7) if we add a new method to an interface, then we have to
track down all implementations of interface and define
implementation of the new method.
ABSTRACT CLASS:
1)a class can inherit only one abstract class
2)may contain non-final variables
3)members can be declared with any access specifier
4)should be inherited using "extends" keyword
5)cannot be instantiated but can be invoked if main() exists
6)faster than interfaces
7)if we add a new method to abstract class, then we've the
option of providing default implementation and therefore all
existing code might work properly.

Is This Answer Correct ?    0 Yes 1 No

Difference between abstract class and interface..

Answer / shashi

abstract class is specific for its sub class, while
interface has common properties for its all classes who
implement it.

Is This Answer Correct ?    0 Yes 1 No

Difference between abstract class and interface..

Answer / mohammad mousa fanasheh

Multiple inheritance:
interface :A class may inherit several interfaces.

Subtract: A class may inherit only one abstract class.


Default implementation:
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.



Speed:
Interface Requires more time to find the actual method in the corresponding classes.

abstract class Faster

Adding functionality (Versioning):
In interface .. 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.

In abstract class ..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 ?    0 Yes 1 No

Difference between abstract class and interface..

Answer / vineet tyagi

The main difference between abstract class and interface
is "Java class can implements more than one interface but
inherit or extends only one abstract class".

Is This Answer Correct ?    0 Yes 2 No

Difference between abstract class and interface..

Answer / wavare santosh

What is an Abstract Class?

An abstract class is a special kind of class that cannot be
instantiated. So the question is why we need a class that
cannot be instantiated? An abstract class is only to be
sub-classed (inherited from). In other words, it only allows
other classes to inherit from it but cannot be instantiated.
The advantage is that it enforces certain hierarchies for
all the subclasses. In simple words, it is a kind of
contract that forces all the subclasses to carry on the same
hierarchies or standards.
What is an Interface?

An interface is not a class. It is an entity that is defined
by the word Interface. An interface has no implementation;
it only has the signature or in other words, just the
definition of the methods without the body. As one of the
similarities to Abstract class, it is a contract that is
used to define hierarchies for all subclasses or it defines
specific set of methods and their arguments. 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.

Is This Answer Correct ?    0 Yes 2 No

Difference between abstract class and interface..

Answer / uttam

1.)
abstract class contains the the incomplete data while
interface contains the complete data.

2.)
the new class in necessary to inherit the abstract class &
give it own body & then it becomes complete
while in case of interface the new class inherits the
interface ti use it`s data contained.

Is This Answer Correct ?    21 Yes 26 No

Difference between abstract class and interface..

Answer / brgkkc

1) Abstract class defines few or none of the methods, but
interface defines all the methods..
2) Abstract classes should have subclasses else that will
be useless..
Interfaces must have implementations by other classes else
that will be useless
3)only an interface can extend another interface, but any
class can extend an abstract class..
4)All variable in interfaces are final by default

Is This Answer Correct ?    444 Yes 531 No

Difference between abstract class and interface..

Answer / versha

Interface: 1)In case if interface it is one contract.The
functions which we define functions we have to make
implements in body.
2)It can come in inheritance chain

Abstract Class:1) In case of Abstract class we have to use
keyword that is"Mustinherit".
2)In that this is not come in inheritance
chain

Is This Answer Correct ?    84 Yes 195 No

Difference between abstract class and interface..

Answer / santhosh

Both are same in functionality...

Is This Answer Correct ?    42 Yes 362 No

Post New Answer

More Dot Net AllOther Interview Questions

What is new in the .net 2.0 class library?

0 Answers  


what is the difference between running an application with and without debugger?

0 Answers   Six Sigma,


question related to table havi colspan and row span

0 Answers   PCS,


Why am I getting an invalidoperationexception when I serialize an arraylist?

0 Answers  


how windows applications different from the console applications?

1 Answers   Six Sigma,






Explain .net mobile selectionlist control? : Microsoft dot net mobile

0 Answers  


Explain Singleton design pattern in .net

0 Answers   Infosys,


How to delete the duplicate records from table(having bulk records)?

4 Answers   BV, iGate,


HttpHendler and HttpModules

0 Answers   PCS, Sopra,


Are there any third party logging components available?

0 Answers  


2. What type of code (server or client) is found in a Code-Behind class?

1 Answers  


9. Oop-Class A has m1 metthode Class B has m1 metthode and C is the calss that inharits A class, A class inharits B class. If Object dim c as new A() c.m1(), Tell me which mettode of class will call

2 Answers   PCS,


Categories