Which of the following statements about the ‘abstract’ keyword in Java is true?

Java MCQ: Which of the following statements about the ‘abstract’ keyword in Java is true?

a) An abstract class cannot have any methods
b) An abstract method must be implemented in a subclass
c) An abstract class can be instantiated directly
d) An abstract method can have a body

Answer:

b) An abstract method must be implemented in a subclass

Explanation:

The abstract keyword in Java is used to declare a class or method that is intended to be extended or implemented by other classes. An abstract method is a method that is declared without a body, meaning it does not contain any implementation. Such methods must be implemented by subclasses that inherit from the abstract class.

Abstract classes cannot be instantiated directly; instead, they are meant to be subclassed. If a subclass does not provide implementations for all abstract methods in the superclass, the subclass must also be declared abstract.

Understanding the use of abstract classes and methods is crucial for designing flexible and extendable code, allowing for the creation of complex class hierarchies.

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