Logo InterviewVault

Welcome back, Sujit Kumar Mishra

SKM

Revision Mode

Document technical questions and best-practice answers.

Cancel

What is the difference between Abstract class and Interface class in Java? 

Difference between Abstract Class and Interface in Java:


Abstract Class:

1: Can have both abstract (without body) and concrete (with body) methods.

2: Can have variables with any access modifier (private, protected, etc.).

3: Can provide some code (implementation) that subclasses can reuse.

4: A class can extend only one abstract class (single inheritance).


Interface:

1: All methods are abstract by default (until Java 8, after which default and static methods are allowed).

2: All variables are public, static, and final (constants) by default.

3: Cannot provide code for methods (except default/static methods).

4: A class can implement multiple interfaces (multiple inheritance).


In short:

1: Use an abstract class when you want to share some code among related classes.

2: Use an interface when you want to define a contract that many classes can follow, even if they are not related.

Ready for commit