Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

What is the difference between and interface and an
abstract class ?

Answer Posted / wilbur j. pereira

What is an Interface?

An interface is a contract, a specification that concrete
classes MUST follow. It defines method signatures but
cannot have any implementations; the latter must be
provided by the classes that implement the interface.

C# differs from C++ in this regard because C++ lacks native
language support for interfaces. As a C++ programmers you
have to create an interface by defining an abstract class
with pure virtual methods.

what is an abstract class.................

An Abstract class lets you define some behaviors and force
your subclasses to provide others.
For example, if you have an application framework, an
abstract class may provide default services such as event
and message handling. Those services allow your application
to plug in to your application framework. However, there is
some application-specific functionality that only your
application can perform. So instead of trying to define
these behaviors, the abstract class can declare abstract
methods.

Differences between Interfaces and Abstract classes Which
we use ?

I. multiple inheritance

A class may implement several interfaces but can only
extend one abstract class.

II. default implementation

An interface cannot provide any code at all, much less
default code. An abstract class can provide complete code,
default code, and/or just stubs that have to be overridden.

III. adding functionality

If you add a new method to an interface, you must track
down all implementations of that interface in the universe
and provide them with a concrete implementation of that
method.
If you add a new method to an abstract class, you have the
option of providing a default implementation of it. Then
all existing code will continue to work without change.

IV. is-a vs -able or can-do

Interfaces are often used to describe the abilities of a
class, not its central identity, e.g. an Automobile class
might implement the Recyclable interface, which could apply
to many otherwise totally unrelated objects.

An abstract class defines the core identity of its
descendants.

********************************************************

There are lost of discussion on the internet about the
Interface vs Abstract class. Also, as base class whether we
have to use interface, abstract class or normal class.

I am trying to point out few considerations on which we can
take decision about Interface vs Abstract class vs Class.

Abstract Class vs Interface

I am assuming you are having all the basic knowledge of
abstract and interface keyword. I am just briefing the
basics.

We can not make instance of Abstract Class as well as
Interface.

Here are few differences in Abstract class and Interface as
per the definition.

Abstract class can contain abstract methods, abstract
property as well as other members (just like normal class).

Interface can only contain abstract methods, properties but
we don?t need to put abstract and public keyword. All the
methods and properties defined in Interface are by default
public and abstract.


//Abstarct Class

public abstract class Vehicles
{
private int noOfWheel;
private string color;
public abstract string Engine
{
get;
set;
}
public abstract void Accelerator();
}

//Interface
public interface Vehicles
{
string Engine
{
get;
set;
}
void Accelerator();
}

We can see abstract class contains private members also we
can put some methods with implementation also. But in case
of interface only methods and properties allowed.

We use abstract class and Interface for the base class in
our application.

This is all about the language definition. Now million
dollar question.

Thanks
Manoj(InfoAxon Technology Limited)


Is This Answer Correct ?    26 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is data binding in oops?

1023


What does <> mean pseudocode?

1113


How many human genes are polymorphic?

1001


write a program that takes input in digits and display the result in words from 1 to 1000

2369


What is destructor give example?

1011


Describe these concepts: Polymorphism, Inheritance and Abstraction.

1138


What are the three parts of a simple empty class?

1979


Is oop better than procedural?

975


Can an interface inherit a class?

1010


what is graphics

2402


class type to basic type conversion

2337


What is encapsulation selenium?

953


Is react oop?

1013


to find out the minimum of two integer number of two different classes using friend function

2075


What is abstract class in oops?

973