0

Hi everybody , please what is differnce between abstract class and interface and how to choose the usefull one

10th Jul 2021, 7:22 AM
‎Abdul Jalil
‎Abdul Jalil - avatar
4 Respostas
+ 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...
10th Jul 2021, 3:58 PM
Yahel
Yahel - avatar
+ 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
10th Jul 2021, 10:11 PM
zemiak
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
11th Jul 2021, 2:11 AM
Jawahirullah
Jawahirullah - avatar
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
11th Jul 2021, 3:06 AM
zemiak