0
Hi everybody , please what is differnce between abstract class and interface and how to choose the usefull one
4 Respuestas
+ 2
Abstract classes are NOT 100% abstract, they can have initialized values or methods in them.
Interfaces ARE 100% abstract, every method must be abstract, every value must be static AND final.
If you need subclasses with some shared attributes and methods- use abstract classes.
If every implementation of the methods in your subclasses are different- use Interface.
Fix me if I'm wrong...
+ 1
interfaces can have default non abstract methods.
but it is still more abstract than class
if there are non final variables as fields, you need abstract class instead.
Usually abstract class implements big interface because it saves time for programmers, then programmers can write just 0ne-two methods instead all interface's methods
0
1)Interfaces don't have any normal methods. But they can have default, private, static methods.
And the variables inside interface are implicitly public static final.
2)but abstract class is the class which contains atleast one abstract method inside it.
As above answers said, we can have any type of methods and variables inside abstract class
0
+ Interface that has single abstract method (SAM), is functional interface and can be implemented by lambda expression, you can't do it with abstract class