+ 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?
6 Respostas
+ 4
As Denise Roßberg implied, multiple inheritance in Java is not possible via abstract or other classes.
+ 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.
+ 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/
+ 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.
+ 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.
+ 1
This is not satisfying...