Difference between abstract class and interface
Answers were Sorted based on User's Feedback
Answer / rajasekhar
Interface:
=>In interface we cann't implement methods.
=>We can write any number of mothods. But all those methods
are by default abstract and public.
Abstract Class:
=>In abstract class none/more abstract and non-abstract
mothods we can declare.
=>We can implement mothods in abstract class.
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / poulami
Interface vs. Abstract class
1.Multiple inheritance
A class may inherit several interfaces.
A class may inherit only one abstract class.
2.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.
3.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
4.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.
5.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.
6.Speed
Requires more time to find the actual method in the
corresponding classes.
Abstrct classes are fast
7.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.
8.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 | 0 No |
Answer / tevendra singh
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 |
Answer / jagan
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 |
Answer / jetandra kumawat ies 1 icot
abstract class in any object is abstract is called abstract
class interface is one or more method abstract abstract
class object p is inhertited but interface object property
inhert
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / sunita
1) abstract classes may contain one or more abstract methods(methods that can't be instantiated). on the other hand interface should contain only abstract methods.
2) abstract classes may implement some of its methods that are not abstract. but interface can't implement any of its method becoz al its methods are abstract.
3)in interfaces all the methods are implicitly abstract,final,static so these modifiers can b omitted but this nit the case wid abstract classes.
4)an important point to note about abstract classes is: they can be subclassed,this sub class implement all the abstract methods that are declared in abstract class.
interfaces provide an alternative to multiple inheritance becoz a class can implement more than one interface.
but an abstract can b sub classed only once.
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / murali
abstract class is very good 1 standard class
interface one of the beautiful face
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / cheshta
1. Main difference is methods of a Java interface are implicitly abstract and cannot have implementations. A Java abstract class can have instance methods that implements a default behavior.
2. Variables declared in a Java interface is by default final. An abstract class may contain non-final variables.
Members of a Java interface are public by default. A Java abstract class can have the usual flavors of class members like private, protected, etc..
3. Java interface should be implemented using keyword “implements”; A Java abstract class should be extended using keyword “extends”.
4. An interface can extend another Java interface only, an abstract class can extend another Java class and implement multiple Java interfaces.
5. A Java class can implement multiple interfaces but it can extend only one abstract class.
Interface is absolutely abstract and cannot be instantiated; 6. A Java abstract class also cannot be instantiated, but can be invoked if a main() exists.
7. In comparison with java abstract classes, java interfaces are slow as it requires extra indirection.
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / sameer
it will help you
http://edugoing.com/qna/index.php?qa=1&qa_1=what-the-difference-between-an-interface-and-abstract-class
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / s.arun
Main difference is methods of a Java interface are implicitly abstract and cannot have implementations. A Java abstract class can have instance methods that implements a default behavior.
Variables declared in a Java interface is by default final. An abstract class may contain non-final variables.
Members of a Java interface are public by default. A Java abstract class can have the usual flavors of class members like private, protected, etc..
Java interface should be implemented using keyword “implements”; A Java abstract class should be extended using keyword “extends”.
An interface can extend another Java interface only, an abstract class can extend another Java class and implement multiple Java interfaces.
A Java class can implement multiple interfaces but it can extend only one abstract class.
Interface is absolutely abstract and cannot be instantiated; A Java abstract class also cannot be instantiated, but can be invoked if a main() exists.
In comparison with java abstract classes, java interfaces are slow as it requires extra indirection.
For m ore detail click on http://edugoing.com/qna/index.php?qa=1&qa_1=what-the-difference-between-an-interface-and-abstract-class
Is This Answer Correct ? | 1 Yes | 1 No |
Define dma? : Dot net architecture
how to make and display a form without title bar?
which would be the best to use inproc,outproc or sql server
What is .net mobile lists. : Microsoft dot net mobile
What is .net mobile automatic paging? : Microsoft dot net mobile
how can u manage sessions ?
Explain <mobile:link> element .net mobile with example? : Microsoft dot net mobile
Difference between type constructor and instance constructor?
Can you give an example of when it would be appropriate to use a web service as opposed to a non-serviced .NET component
How can i create only one instance of class and thus doesn't allow creating any more instances?
how do you hide maximize,minimize and close box at the form title bar?
How will you do windows authentication and what is the namespace?