Difference between abstract class and interface

Answers were Sorted based on User's Feedback



Difference between abstract class and interface..

Answer / vivek sharma

An abstract class may or may not have abstract method,but
it is useless without abstract method ,so an abstract class
should have atleast single abstract method.
while in case of an interface it is hardcode that an
interface can have only the abstract methods with it.

Is This Answer Correct ?    18 Yes 14 No

Difference between abstract class and interface..

Answer / deepa

Interface is used for achive Multiple inheritance.

Abstract class is used for defining the methods.

Is This Answer Correct ?    3 Yes 0 No

Difference between abstract class and interface..

Answer / saqib khan mca 2009 galgotia g

1>Abstract class can have implementations of some methods
while interface can't have any implementations but
declarations of methods.

2>Abstract class can use various access modifiers while
interface doesn't use any access modifiers.

3>Abstract class doesn't support multiple inheritance while
interface's major use is to implement multiple and hybrid
inheritance.

4>Abstract class can have properties,data members,
constructors,static,const,readonly etc.while interface
doesn't implement these but properties.

Is This Answer Correct ?    3 Yes 0 No

Difference between abstract class and interface..

Answer / sreekanth madamanchi

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

2. Only an interface can extend another interface, but any
Class can extend an abstract class..
3. Class can inherit only one abstract class, but class can
implement more than one interface
4. An abstract class can contain constructors, but
interface can’t contain any constructors

5. An abstract class can’t support multiple inheritances,
but an interface can support multiple inheritances.
EX:- class A extends AbstractClass
Class A implements interface1, interface2

6. We can use various access modifiers to variables. such
as abstract, protected, internal, public in Abstract Class,
but all of the variables in an interface are implicitly
(Default) static and final.

7. An abstract class can contain abstract and non-abstract
methods, but interface contains only abstract methods. If
we declare the method without having abstract, by default
it takes that method as abstract method

Is This Answer Correct ?    2 Yes 0 No

Difference between abstract class and interface..

Answer / cinda

1)abstact class may or may not include abstract methods(An
abstract method is a method that is declared without an
implementation )
Bt interface is a class with only signature of a
methods.class that implements an interface must implement
all of the interface's methods.

example for abstract class:-
public abstract class x {
int x,y;//definitions
void draw(){}//non abstract methods
abstract void YY();//abstract methods
}

example for interface:-
interface x
{
void sample(int y);//signature of amethod
}

2)abstract class can inherit from only one class(it doesnt
support multiple inheritance)

public abstract class x {
int x,y;//definitions
void draw(){}//non abstract methods
abstract void YY();//abstract methods
}
class y extends x{
void draw(){
....
}
but interface supports multiple inheritance

Interface interface1{
.....
}

Interface interface2{
.....
}

Interface interface3{
.....
}
public Interface x extends interface1,interface2,interface3{

}

In Interfaces , it was noted that a class that implements
an interface must implement all of the interface's methods.
It is possible, however, to define a class that does not
implement all of the interface methods, provided that the
class is declared to be abstract. For example,
abstract class X implements Y {
// implements all but one method of Y
}

class XX extends X {
// implements the remaining method in Y
}

In this case, class X must be abstract because it does not
fully implement Y, but class XX does, in fact, implement Y.

Is This Answer Correct ?    2 Yes 0 No

Difference between abstract class and interface..

Answer / kannan

Abstract class: We no need to create the object for the
abstract class, abstract class must be sub classed.
Abstract class may contain its default implementation.
Interface: It is just like a check list. All the methods is
interface should be a public.It contain only the method
declaration. If one class implements the interface means,
that class should give the implementation for the all the
methods.

Is This Answer Correct ?    2 Yes 0 No

Difference between abstract class and interface..

Answer / vikash kumar

1. interface contains methods that must be abstract;
abstract class may contain concrete methods.
2. interface contains variables that must be static and
final; abstract class may contain non-final and final variables.
3. members in an interface are public by default,
abstract class may contain non-public members.
4. interface is used to "implements"; whereas abstract
class is used to "extends".
5. interface can be used to achieve multiple inheritance;
abstract class can be used as a single inheritance.
6. interface can "extends" another interface, abstract
class can "extends" another class and "implements" multiple
interfaces.
7. interface is absolutely abstract; abstract class can
be invoked if a main() exists.
8. interface is more flexible than abstract class because
one class can only "extends" one super class, but
"implements" multiple interfaces.
9. If given a choice, use interface instead of abstract
class.

Is This Answer Correct ?    2 Yes 0 No

Difference between abstract class and interface..

Answer / chaitu

Abstract classes can have zero or more abstract methods.
In Abstract class even we can write methods with implementations.

But

In Interface by default all the methods are public and abstract. so in interface we can not write the implemented methods.

Is This Answer Correct ?    2 Yes 0 No

Difference between abstract class and interface..

Answer / ved prakash mishra

ABSTRACT CLASS:-An abstract class declares common attributes and behaviors of the various classes in a class hierarchy. An abstract class typically contains one or more abstract methods that subclasses must override if the subclasses are to be concrete. The instance variables and concrete methods of an abstract class are subject to the normal rules of inheritance.

Attempting to instantiate an object of an abstract class is a compilation error.
Failure to implement a superclass's abstract methods in a subclass is a compilation error unless the subclass is also declared abstract.
we can use abstract superclasses to declare variables that can hold references to objects of any concrete class derived from those abstract classes. Programs typically use such variables to manipulate subclass objects polymorphically. We also can use abstract superclass names to invoke static methods declared in those abstract superclasses.

interface:- A subclass can inherit "interface" or "implementation" from a superclass. Hierarchies designed for implementation inheritance tend to have their functionality high in the hierarchyeach new subclass inherits one or more methods that were implemented in a superclass, and the subclass uses the superclass implementations. Hierarchies designed for interface inheritance tend to have their functionality lower in the hierarchya superclass specifies one or more abstract methods that must be declared for each concrete class in the hierarchy, and the individual subclasses override these methods to provide subclass-specific implementations.

Is This Answer Correct ?    2 Yes 0 No

Difference between abstract class and interface..

Answer / leeladhar

abstract means hiding some thing and interface are use for
multiple inheritence because a subclass can't extend by two
base class it can implement by two interface only.

in abstract class some method will be abstract or some
method will be non abstract.
for abstract method you need subclass that will be define
base class's abstract method.
subclass is not mendatory to all abstact class.

in interface all method will be abstract type so for that
subclass is mendatory that will define method.

Is This Answer Correct ?    2 Yes 1 No

Post New Answer

More Dot Net AllOther Interview Questions

Explain dotnet framework ?

0 Answers  


Explain about cookie less session state? : .NET Architecture

0 Answers  


What is a managed code? : Dot net architecture

0 Answers  


Can you explain scriptmanager control?

0 Answers  


how to make and display a form without title bar?

0 Answers   Six Sigma,






Explain .net mobile selectionlist control? : Microsoft dot net mobile

0 Answers  


What is cache coherency? : Dot net architecture

0 Answers  


Explain pipelining? : .NET Architecture

0 Answers  


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

0 Answers  


Which is the best institute in chennai to learn DotNet? Please help.

48 Answers   HCL, Infosys, NIIT,


How to implement the display in the class printdoc (how to resolve the naming conflict) a: no naming conflicts

0 Answers  


What is an asssembly qualified name? Is it a filename? How is it different?

0 Answers  


Categories