There are some basic difference between abstract class and Interface
Abstract classInterface
1- There are must be used 'abstract' keyword to define an abstract class.
Here 'interface' is used to define Interface before its name.
e.g abstract class <class_name>
e.g interface <interface_name>
2- An abstract class can contain abstract abstract methods and also regular methods.
In interface it can contain only methods
3- Abstract class is generally inherits in derived class it is denoted with colon(:)
Interface is implement in regular class and it also used ( : ) for implementation.
4- In abstract class there are not necessary to call of all methods of abstract class except all defined abstract method .
In interface there is must to call all declared method in interface because all methods are by default public and abstract.
5- Instance variable can be declare in abstract class.
It is not allow to declare instance in interface
6- In abstract class there is must use abstract keyword to declare a abstract method and also used 'override' keyword when it override in other regular class.
In interface methods are defined without using 'abstract' keyword and also does not need to use 'override' keyword to override that methods in regular class.
exe-
abstract class Animal { interface InterfaceClass { public abstract void Dog(); void Night(); // method without body public void Cat() { } Console.WriteLine('Cat cry like meuuuu'); class Inte :InterfaceClass{ } public void Night(){ } Console.WriteLine('everyday '); //override class Flower : Animal { } public override void Dog() { } Console.WriteLine('Dog is bark'); class Interface { } static void Main(String[] arg) {
} Inte inte =new Inte(); class Abstract { inte.Night(); static void Main(string[] arg) { } Flower rose = new Flower(); } rose.Dog(); rose.Cat(); }
}
note- we can pass parameter in abstract method in Abstract class and Interface. In both abstract class and interface, methods are declare without his body. Its being terminate by semicolon (;).
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Difference between Abstract class and Interface
There are some basic difference between abstract class and Interface
Abstract class Interface
abstract class Animal { interface InterfaceClass {public abstract void Dog(); void Night(); // method without body
public void Cat() { }
Console.WriteLine('Cat cry like meuuuu'); class Inte :InterfaceClass{
} public void Night(){
} Console.WriteLine('everyday '); //override
class Flower : Animal { }
public override void Dog() { }
Console.WriteLine('Dog is bark'); class Interface {
} static void Main(String[] arg) { } Inte inte =new Inte();
class Abstract { inte.Night();
static void Main(string[] arg) { }
Flower rose = new Flower(); }
rose.Dog();
rose.Cat();
}
}
note- we can pass parameter in abstract method in Abstract class and Interface. In both abstract class and interface, methods are declare without his body. Its being terminate by semicolon (;).