What is the difference between abstract class and interface in terms of implementation? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

What is the difference between abstract class and interface in terms of implementation?

30th Aug 2018, 7:44 AM
Divyani Singh
Divyani Singh - avatar
2 Answers
30th Aug 2018, 11:37 AM
Maninder $ingh
Maninder $ingh - avatar
+ 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.
11th Sep 2018, 9:10 AM
shiwangee pathak
shiwangee pathak - avatar