+ 2
What is the difference between abstract class and interface in terms of implementation?
2 Réponses
+ 3
+ 1
Divyani , let's take an example for abstract class :
a class Animal has many methods like sound(), eyes(), legs() and many more. And we know that every animal has it's own different sound() so we can declare sound() method as abstract method which has no body and also every derived class has to defined it with own implementation.
Because Animal class has an abstract method so Animal class has to be declare abstract class and an abstract class can contain non-abstract method just like legs() for walking ,which can be define in abstract class.
Now , interface :
Because in c# and java we can not achieve multiple inheritance therefore we bring a concept of interface through which we can achieve multiple inheritance. An interface can only have abstract methods. Otherwise I don't think that interface is necessary.