Definition |
A blueprint for creating objects that can have state and behavior. |
A class that cannot be instantiated and can contain both abstract and concrete methods. |
A contract that defines a set of abstract methods without implementation. |
Instantiation |
Can be instantiated using the new keyword. |
Cannot be instantiated. |
Cannot be instantiated. |
Keyword |
class |
abstract class |
interface |
Method Implementation |
Can contain fully implemented methods. |
Can contain both abstract and concrete methods. |
Prior to Java 8, only abstract methods. Java 8+ supports default and static methods. |
Constructors |
Can have constructors. |
Can have constructors, but they cannot instantiate objects. |
Cannot have constructors. |
Inheritance |
Supports single inheritance. |
Supports single inheritance. |
Can be implemented by multiple classes (Multiple Inheritance). |
Access Modifiers |
Can use any access modifier. |
Can use any access modifier. |
Methods are public and abstract by default (prior to Java 8). |
Fields/Variables |
Can have instance variables. |
Can have instance variables and final static constants. |
Can only have public static final constants. |
Method Overriding |
Methods can be overridden in subclasses. |
Abstract methods must be implemented in subclasses. |
All abstract methods must be implemented in implementing classes. |
Usage Purpose |
To define common properties and behavior. |
To provide a base class with common methods and optional method implementation. |
To define a set of rules/behaviors that a class must follow. |
Multiple Inheritance |
Not supported. |
Not supported. |
Supported using multiple interfaces. |
Java 8+ Features |
N/A |
Can have default and static methods but not private methods. |
Can have default, static, and private methods. |
Use Case |
When a fully defined class with implementation is needed. |
When some methods need to be implemented and some need to be defined by subclasses. |
When a contract or a set of behaviors needs to be defined without implementation. |