Difference between abstract class and interface

Answers were Sorted based on User's Feedback



Difference between abstract class and interface..

Answer / sando

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 PHP doesn't support multiple inheritance,
interfaces are used to implement multiple inheritance.
Both Together

When we create an interface, we are basically creating a set
of methods without any implementation that must be
overridden by the implemented classes. The advantage is that
it provides a way for a class to be a part of two classes:
one from inheritance hierarchy and one from the interface.

When we create an abstract class, we are creating a base
class that might have one or more completed methods but at
least one or more methods are left uncompleted and declared
abstract. If all the methods of an abstract class are
uncompleted then it is same as an interface. The purpose of
an abstract class is to provide a base class definition for
how a set of derived classes will work and then allow the
programmers to fill the implementation in the derived classes.

Is This Answer Correct ?    0 Yes 0 No

Difference between abstract class and interface..

Answer / a.srinivas

1)we can't create directly an object of interface
2)inter faces have only abstract methods where as abstract class have may concrete methods and abstract methods
3)interfaces are common reusuable
but abstract class are specific reusuable

Is This Answer Correct ?    0 Yes 0 No

Difference between abstract class and interface..

Answer / lavi

C++ supports only the abstract class not in interface.but
java support interface.the interface created for avoid
multiple inheritence concept in C++.

Is This Answer Correct ?    0 Yes 0 No

Difference between abstract class and interface..

Answer / amulraj.m

1)An abstract class is a special kind of class that cannot be instantiated,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.
2)Abstract class should be used as base class.An interface is derived from all classes.

Is This Answer Correct ?    0 Yes 0 No

Difference between abstract class and interface..

Answer / b.harendra

what is the difference between abstractclass and interface?
Re: Difference between abstract class and interface
Answer


Abstract classes can have implementations for some of its
members (Methods), but the inteface class can't have
implementation for any of its members.

Is This Answer Correct ?    0 Yes 0 No

Difference between abstract class and interface..

Answer / kajal

In interface there is no implementation of any method.In
Interface you can declare methods there but you can't not
implement it.

Is This Answer Correct ?    0 Yes 0 No

Difference between abstract class and interface..

Answer / n.srinivas goud

1) An abstract class can have abstract methods and
concrete methods whereas an interface can have only
abstract methods.
2) An abstract class can have constructor where an
interface cant have constructors.

Is This Answer Correct ?    0 Yes 0 No

Difference between abstract class and interface..

Answer / er. prabhat, tcs

biggest difference:

purpose of class is to represent objects
while
purpose of interface isn't to represent objects.....by
interface programmer gets only method names..but body is 2b
given by him....
now a question arises in my mind...if i'm giving body of
method then why shouln't i giv name too.....hmmmm.....

bete...interface ke methods ke body to programmer deta hai
bt chalata koi aur hai...it is not programmer who calls
these methods..


chinta mat karo...i'm giving example.....
EVENT HANDLING :ActionListener ko implement kiya,
actionPerformed() ki body di....magar actionPerformed() ko
humne nahi chalaya..note it

Is This Answer Correct ?    0 Yes 0 No

Difference between abstract class and interface..

Answer / prathap

In Abstract class we are having both concrete methods and
abstract methods.Concrete methods means providing
implementation for that method but abstract method cant
provide implemention for that method.we can implement
abstract methods in the sub class..
In Interface we are having un implemented methods but we
can provide impletion for that methods in the implementation
class...
the main difference is Abstract class is having implemented
and un implemented methods but an interface is having only
unimpleted methods ..

Is This Answer Correct ?    0 Yes 0 No

Difference between abstract class and interface..

Answer / deepak jindal

ABSTRACT CLASS:
1) we can't create object of abstract class.
2) we can declare a variable.
3) we can make normal method and abstract method.
4) we can't make method body with abstract method.
5) in derived class we can use abstract method by override
keyword.
6) we can't use multiple inheritance in abstract class.
7) Absrtact class can be extended by only one class;
Interface can be implemented by more than one class;
ie. class can inherit only one abstract class


8)Abstract classes can inherit interfaces while interfaces
cannot inherit abstract classes
but class can implement more than one interface.
9) The members of the interface are public with no
implementation. Abstract classes can have protected
parts,static methods, etc.

10)An abstract class can contain fields,
constructors, or destructors and implement properties. An
interface can not contain fields, constructors, or
destructors and it has abstractmethod,property's signature
but no implementation etc.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Dot Net AllOther Interview Questions

What is the numeric attribute of the textbox control in .net mobile? : Microsoft dot net mobile

0 Answers  


What is the .net class that allows the retrieval of a data element using a unique key?

0 Answers  


can Array contains different datatypes ?

5 Answers  


What are the major differences between services and web services?

0 Answers  


Explain the number or character entered through keyboard gets converted to equivalent ascii code & it get stored on ram in the binary form. What is the exact procedure. : Dot net architecture

0 Answers  






Explain about .net garbage collector?

0 Answers  


What is .net mobile images control. Explain with an example? : Microsoft dot net mobile

0 Answers  


What is different about namespace declaration when comparing that to package declaration in java?

0 Answers  


what is the use of SQL command builder class in C#.net? Explain how can we execute a stored procedure using C#.Net? What is the difference between .DLL and .EXE?

2 Answers  


Explain the process of gc?

0 Answers  


HI THIS IS THIRUMAL. I AM COMPLETED MY MCA IN 2009 WITH 64%. NOW I AM LOOKING FOR A JOB(FRESHER)IN HYDERABAD.PLEASE IF YOU FIND ANY OPENINGS IN ANY COMPANY SEND IT TO MY MAIL ID PLEASE.. SKILL SET : C,C++,C#.NET,ASP.NET,ADO.NET,SQL SERVER, SSIS,SSRS EMAIL ID : THIRU104@GMAIL.COM THANKS & REGARDS D.THIRUMAL

1 Answers  


which would be the best to use inproc,outproc or sql server

2 Answers   Ness Technologies,


Categories