Difference between abstract class and interface

Answers were Sorted based on User's Feedback



Difference between abstract class and interface..

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

Difference between abstract class and interface..

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

Difference between abstract class and interface..

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

Difference between abstract class and interface..

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

Difference between abstract class and interface..

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

Difference between abstract class and interface..

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

Difference between abstract class and interface..

Answer / murali

abstract class is very good 1 standard class
interface one of the beautiful face

Is This Answer Correct ?    0 Yes 0 No

Difference between abstract class and interface..

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

Difference between abstract class and interface..

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

Difference between abstract class and interface..

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

Post New Answer

More Dot Net AllOther Interview Questions

How cache coherency is eliminated? : Dot net architecture

0 Answers  


What is the difference between machine config vs. Web config : Dot net architecture

0 Answers  


Explain the five stages in a dlx pipeline? : .NET Architecture

0 Answers  


how to create applications by using Visual Studio 2012?

0 Answers   TryTechnicals Pvt Ltd,


How do you handle this COM components developed in other programming languages in .NET?

0 Answers   InfoAxon Technologies,






what is managed code and managed data?

2 Answers   Six Sigma,


what is tracing? Where it used?

0 Answers  


7. Oop-Diff B/w Interfacse and abstract class.

3 Answers   PCS,


What's the difference between an application and a program?

0 Answers  


Do you know textbox and textview controls of .net mobile? : Microsoft dot net mobile

0 Answers  


What is a service class?

0 Answers  


How do I stop a thread?

0 Answers  


Categories