+ 2

What is the need of interface, if the work done by interface ..can also be done by an abstract class?

interface have abstract methods. Abstract class have both abstract or non abstract methods, if we are not declaring any non abstract then it is just like an interface. Then what is the need of interface?

13th Aug 2019, 7:07 PM
Arpita Jha
6 Réponses
+ 4
As Denise Roßberg implied, multiple inheritance in Java is not possible via abstract or other classes.
14th Aug 2019, 1:58 AM
Sonic
Sonic - avatar
+ 4
Arpita Jha interface and abstract class look like same but actually they both are different.Abstract class can have both abstract function as well as complete definition function.but interface can only have abstract function or you can say interface is a fully abstract class.With the help of interface you can achieve multiple inheritance in java or c#. Abstract class dont work with multiple inheritance.
14th Aug 2019, 2:18 AM
Maninder $ingh
Maninder $ingh - avatar
+ 3
Interfaces are good for multiple inheritance. For example you have three interfaces then a class can implement them all. For more differences between abstract class and interface: https://www.google.de/amp/s/www.geeksforgeeks.org/difference-between-abstract-class-and-interface-in-java/amp/
13th Aug 2019, 11:43 PM
Denise Roßberg
Denise Roßberg - avatar
+ 2
In abstract class, if the parent class extending abstract class does not write any method's body then the child class inheriting parent class can write the method's body. But the method's body should be written either by the class itself or by its child class. But in the case of interface, the class implementing the interface will have to write the method's body in it. It cannot be passed in child class. Basically if you know that a child class of a class will use a method so you can fix that method's definition by writing it in a abstract class. It is basically useful when you have a large scale business/company, you can fix your method's definition and everyone will have to rely on it. I hope it helps you.
13th Aug 2019, 7:31 PM
Chetali Shah
Chetali Shah - avatar
+ 2
Basically they look like same in nature but in actual they are totally different and have import role in java. Coming to the point of Abstract class if one of the method in class is Abstract then the class called Abstract it may have one of more abstruse method. But in case or interface it's basically use to create multiple inheritance in java. So all the methods have to abstruct and user have to override it.
18th Feb 2020, 11:21 AM
Krishnanshu Dey
Krishnanshu Dey - avatar
+ 1
This is not satisfying...
13th Aug 2019, 7:39 PM
Arpita Jha