What is the difference between an abstract class and an interface when Java 8 introduced default methods in interfaces?
- An abstract class can contain both abstract and concrete methods, whereas an interface can only have abstract methods.
- An abstract class cannot be extended, but an interface can be implemented.
- An abstract class cannot have any methods with default implementations, while an interface can have default methods.
- An abstract class cannot have constructors, but an interface can have default constructors.
In Java 8, interfaces were enhanced to support default methods, which provide a default implementation. The key difference between an abstract class and an interface is that an abstract class can have both abstract and concrete methods, whereas an interface can only have abstract methods. This allows for multiple inheritance of behavior through interfaces while maintaining the ability to inherit state through abstract classes.
Loading...
Related Quiz
- What is the purpose of the start() method in a JavaFX application?
- How can we gracefully shutdown an ExecutorService?
- Which method is used to display a stage in JavaFX?
- Which index of a multi-dimensional array represents the row index in Java?
- Envision a scenario where you need to update a user’s details and also log the changes in an audit table. This operation needs to ensure data integrity and consistency. How would you achieve this using JDBC?