group-icon
Java Developers
Group for Java developers and programmers. Ask questions and get answers related to Java programming
270 Members
Join this group to post and comment.
Gaurav Prasad
Gaurav Prasad
Computer Science
14 Jan 2019

Difference between abstract class and interface of java?

Is there a difference in types of methods and data members between both of them? 

Prince Rathore
Prince Rathore
Computer Science
4mos ago

Yes, there is a difference. 

1.Variables:

                The abstract class can have static, non-static, final and non-final variables whereas

                An interface can have only static and final variables.

2. Methods:

                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.

Gaurav Prasad
Gaurav Prasad
Computer Science
4mos ago

Bro well done.  Im happy with your  answer.

Shruthi Pillai
Shruthi Pillai
Information Technology
4mos ago

Abstract class

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”.

Interface

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” .

DHIRAJ LOTLIKAR
DHIRAJ LOTLIKAR
Information Technology
4mos ago

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.

Gaurav Prasad
Gaurav Prasad
Computer Science
4mos ago

thanks for all your efforts.