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

Java MCQ: What is the difference between an interface and an abstract class?

a) Interfaces can have default methods, abstract classes cannot
b) Interfaces support multiple inheritance, abstract classes do not
c) Abstract classes can have constructors, interfaces cannot
d) All of the above

Answer:

d) All of the above

Explanation:

Interfaces and abstract classes in Java serve different purposes. Interfaces support multiple inheritance, while abstract classes do not. Abstract classes can have constructors and concrete methods, whereas interfaces, prior to Java 8, could only have abstract methods. However, from Java 8 onwards, interfaces can have default and static methods.

Understanding the differences between interfaces and abstract classes is key to choosing the right structure for your Java applications.

Reference links:

https://www.rameshfadatare.com/learn-java-programming/
https://www.javaguides.net/p/java-tutorial-learn-java-programming.html

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top