0% found this document useful (0 votes)
107 views2 pages

Difference Between Abstract Class and Interface

1. An abstract class can contain both abstract and non-abstract methods, while an interface can only contain abstract methods. 2. An abstract class can provide implementation for interfaces but an interface cannot provide implementation for abstract classes. 3. The main differences are that abstract classes support single inheritance while interfaces support multiple inheritance, abstract classes can contain constructors and non-public variables/methods while interfaces members are public, and abstract classes can provide partial implementation while interfaces achieve full abstraction.

Uploaded by

Mangesh Deshmukh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
107 views2 pages

Difference Between Abstract Class and Interface

1. An abstract class can contain both abstract and non-abstract methods, while an interface can only contain abstract methods. 2. An abstract class can provide implementation for interfaces but an interface cannot provide implementation for abstract classes. 3. The main differences are that abstract classes support single inheritance while interfaces support multiple inheritance, abstract classes can contain constructors and non-public variables/methods while interfaces members are public, and abstract classes can provide partial implementation while interfaces achieve full abstraction.

Uploaded by

Mangesh Deshmukh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Difference between abstract class and interface

Abstract class and interface both are used to achieve abstraction where we can declare the abstract
methods. Abstract class and interface both can't be instantiated.

But there are many differences between abstract class and interface that are given below.

Abstract class Interface

1) Abstract class can have abstract and Interface can have only abstract methods. Since Java
non-abstractmethods. 8, it can have default and static methods also.

2) Abstract class doesn't support Interface supports multiple inheritance.


multiple inheritance.

3) Abstract class can have final, non- Interface has only static and final variables.
final, static and non-static variables.

4) Abstract class can provide the Interface can't provide the implementation of
implementation of interface. abstract class.

5) The abstract keyword is used to The interface keyword is used to declare interface.
declare abstract class.

6) An abstract class can extend another An interface can extend another Java interface only.
Java class and implement multiple Java
interfaces.

7) An abstract class can be extended An interface can be implemented using keyword


using keyword "extends". "implements".

8) A Java abstract class can have class Members of a Java interface are public by default.
members like private, protected, etc.

9)Example: Example:
public abstract class Shape{ public interface Drawable{
public abstract void draw(); void draw();
} }

Simply, abstract class achieves partial abstraction (0 to 100%) whereas interface achieves fully
abstraction (100%).
Class and Interface:

The similarities are:

 a. Both are java basic object types.


 b. Both can contain variables and methods (class methods have implementation code whereas
the interface methods can only have declarations)
 c. Both be inherited using Inheritance (extends keyword for classes and implements keyword for
interfaces)

2. Differences between Class and Interface are:

CLASS INTERFACE

Supports only multilevel and hierarchical Supports all types of inheritance –


inheritances but not multiple inheritance multilevel, hierarchical and multiple

"implements" keyword should be used to


"extends" keyword should be used to inherit inherit

Should contain only concrete methods (methods Should contain only abstract methods
with body) (methods without body)

The methods can be of any access specifier (all the


four types) The access specifier must be public only

Methods can be final and static Methods should not be final and static

Variables can be private Variables should be public only

Can have constructors Cannot have constructors

Cannot have main() method as main() is a


Can have main() method concrete method

You might also like