Difference between abstract class and interface of java?
Is there a difference in types of methods and data members between both of them?
Yes, there is a difference.
The abstract class can have static, non-static, final and non-final variables whereas
An interface can have only static and final variables.
The abstract class can have static, non-static, abstract, and concrete methods whereas
An Interface can only have an abstract method ( static and default too from Java 1.8)
3. Accessibility of Data Members:
The abstract class can have members like private, protected, public etc. whereas
Interface members are public by default.
I hope u understood, if I have missed out anything or if u want a detail explanation, do comment.
Bro well done. Im happy with your answer.
Methods and members of an abstract class can be defined with any visibility.It doesnot support multiple inheritance. Abstract class can provide the implementation of interface. Abstract class can be extended using keyword “extends”.
Methods of an interface must be defined as public. It support multiple implementations. Interface can’t provide the implementation of abstract class . A Java interface can be implemented using keyword “implements” .
Abstract class or the interface both have to implement some type of method and the method that they implement are called abstract method. All the abstract method is a method that doesn't contain a body. An abstract class which usually contains atleast one abstract method. It is also possible for the class to have no method at all. This is done in order to prevent the class from being instantiated on its own. If there is a unique and generalized methods that your subclasses will inherit then you should use Abstract Class as the super class.
Interface only contain abstract class. Every single method in your abstract class will have no method in it. Every variable present in interface are static, public and final.
thanks for all your efforts.