Difference between abstract class and interface
Answers were Sorted based on User's Feedback
Answer / bijayalaxmi pradhan
1.In side an abstract class some of the methods are
abstract and some methods are concrete.But incase of an
Interface all methods are abstract().
2.An abstract class cannot support multiple inheritance,
but an interface can support multiple.
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / prada
Abstract classes can inherit interfaces while
interfaces cannot inherit abstract classes
but class can implement more than one interface.
The members of the interface are public with no
implementation. Abstract classes can have protected
parts,static methods, etc.
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / ratikant patra
1.*Abstract class may contain abstract methods,constru-
-ctors,concrete methods,fields....
*interface only contain signature of methods and
fields.
2. *All access specifiers are allowed to class members in
abstract class.By default scope is package or public
depends on programming.
*But data fields and method signatures bydefault final
and public.
****WE KNOW JVM TREATS FINAL METHODS AS INLINE. SO, DYNAMIC-
POLYMORPHISM THROUGH INTERFACE IS FASTER THAN OTHER.
************
3.Abstract class always a super class,only can beextended.
But interface only can be implimented.
4.Code reusability possible by extending abstract classes
*But code reusability not possible using interface.
5.Abstract class is used when programmer need to maintain
property of super class in sub classes i.e. programmer
may override complete methods(but bound to redefine
abstract methods.unless sub class becomes abstract).
*In case of classes implimenting interface must define
all the methods.
6.At a time we can extend only abstract class.
*But we can impliment many interfaces to a class.
RATIKANT PATRA,KIST,BBSR
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / ashish gupta
1)Abstract class can have either declaration or definition
of any method,however an interface must declare a method
and it can not define it.
2)An interface makes some sort of contract to its
implementing classes to define all the declared methods
within those classes.
3)A class/subclass should Extend the abstract class while a
class/subclass should Implement the interface.
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / khaleek ahmad
Abstract class is a special kind of class which can not be
instantiated while Interface is an Entity. You can define
some methods in Abstract class but can not in interface
For more detail see at
http://interview-preparation-for-you.blogspot.com/2010/10/difference-between-abstract-class-and.html
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / karthick
Unlike interfaces, abstract classes can contain fields that
are not static and final, and they can contain implemented
methods. Such abstract classes are similar to interfaces,
except that they provide a partial implementation, leaving
it to subclasses to complete the implementation. If an
abstract class contains only abstract method declarations,
it should be declared as an interface instead.
Multiple interfaces can be implemented by classes anywhere
in the class hierarchy, whether or not they are related to
one another in any way. Think of Comparable or Cloneable,
for example.
By comparison, abstract classes are most commonly subclassed
to share pieces of implementation. A single abstract class
is subclassed by similar classes that have a lot in common
(the implemented parts of the abstract class), but also have
some differences (the abstract methods).
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / vikas patel
A metho without body it's called abstract method and class
contain the abstract method it's called abstract class..
Interface is the collection of the inheritance..
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / pankaj
Abstract class can have abstract methods as well as non-abstract(normal methods).
Abstract class is not instantiated.
Abstract method of abstract class always get body from it's sub class.
Abstract method's are always call by Abstract class itself not it's subclass. ex- event handler
Abstract method's must be overridden by it's subclass
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / rama krishna
Abstract class:
*A class of only Concrete or only Abstract or both.
*Any java class can extend only one abstract class.
*It won’t force the programmer to implement/override all its methods.
*It takes less execution time than interface.
* It allows constructor.
This class can’t be instantiated directly.
A class must be abstract when it consist at least one abstract method.
It gives less scope than an Interface.
It allows both variable & constants declaration.
It allows methods definitions or declarations whenever we want.
It gives reusability hence it can’t be declared as “final”.
Interface:
only abstract methods.
A class can implements any no. of interfaces
(this gives multiple interface inheritance )
It forces the programmer to implement all its methods
Interface takes more execution time due to its complex hierarchy.
* It won’t allow any constructor.
It can’t be instantiated but it can refer to its subclass objects.
It gives more scope than an abstract class.
By default, methodspublic abstract
variablespublic static final.
It allows methods declarations whenever we want . But it involves complexity.
Since they give reusability hence they must not be declared as “final”.
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / varaprasad
An abstract class will have non abstract methods, but an
interface will have pure abstract methods.
Is This Answer Correct ? | 0 Yes | 0 No |
What is .net viewstate?
which tag i need to use manually to bind columns in a datagrid ?
What is the purpose of Accordian in jquery? Where it can be used?
what are constructors and destructors?
Explain the difference between primary & secondary storage device? : Dot net architecture
how would you manage data if u were not to use sessions or cookies ?
How can I write my own .NET host?
What is the purpose of Treeview control?
What is VSS? Use of VSS? How can we use VSS in our Application?
What is cookie less session?
Whats new features in Visual Studio 2012?
How is the using() pattern useful? What is idisposable?