Java MCQ: Which of the following is true about the ‘abstract’ keyword in Java?
Answer:
Explanation:
The abstract
keyword in Java is used to define abstract classes and methods. An abstract class cannot be instantiated, meaning you cannot create an object of an abstract class directly. It is meant to be subclassed, where its abstract methods (methods without a body) are implemented in the subclasses.
When a class contains one or more abstract methods, it must be declared abstract. This ensures that the class cannot be instantiated on its own and must be extended by another class that provides concrete implementations for the abstract methods.
Understanding the role of abstract classes and methods is essential for implementing inheritance and creating flexible and reusable code structures in Java.
Reference links:
https://www.rameshfadatare.com/learn-java-programming/
https://www.javaguides.net/p/java-tutorial-learn-java-programming.html