Junior
Mis vahe on abstraktsete klasside ja liideste vahel?
sobes.tech AI
Vastus AI-lt
Abstract class:
- Can contain abstract (without implementation) and concrete (with implementation) methods.
- Can contain fields (instance variables).
- Can have constructors.
- Allows single inheritance (one class can inherit from an abstract class).
- Used to define the basic structure and common behavior for related classes.
Interface:
- Can contain only abstract methods (some languages, like Java from version 8, allow default and static methods with implementation).
- Cannot contain instance fields (only constants).
- Cannot have constructors.
- Allows multiple implementation (one class can implement multiple interfaces).
- Used to define a contract that classes must fulfill.