What is the difference between an interface and an abstract class?

Asked 2 years ago, Updated 2 years ago, 121 views

What is the difference between an interface and an abstract class?

oop java interface abstract-class

2022-09-22 15:01

1 Answers

I think the main difference between an interface and an abstract class is class or not. For comparison, an interface cannot have variables, but it can have abstract classes.

Also, the difference between class or not is that Java does not allow multiple inheritance due to various problems. However, you can get the benefit of multiple inheritance from the interface.

If you use an abstract class, it's impossible to inherit an abstract class again if one class inherits another class, but it's possible to implement the method in it by implementing the interface.

There are two abstract classes and two interfaces to support polymorphism.

Reference site


2022-09-22 15:01

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.