Difference between abstract class and interface

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

I can't be bothered with cas. Can I turn it off?

692


Explain the race around condition? : .NET Architecture How can it be overcome? : .NET Architecture

656


What is textbox control of .net mobile? : Microsoft dot net mobile

790


12. Types of polymorphisem[Run and Design Exp.]

1806


What are different types that a variable can be defined and their scopes ?

801






how to change row background color in gridview

714


Define the mesi? : Dot net architecture

707


What are the different pipelining hazards? : Dot net architecture

769


What is cache coherency? : Dot net architecture

660


how to delete the record using data reader

2050


Explain about validation?

761


Name some changes done since version 3.0?

696


How cache coherency is eliminated? : Dot net architecture

651


Explain pipelining? : Dot net architecture

742


What is msil, and why should my developers need an appreciation of it if at all?

741