Which keyword is used to define an abstract class in Java?

Enhance your coding skills and prepare for advanced coding tests with flashcards and multiple choice questions, complete with hints and explanations. Get ahead in your coding career!

In Java, the keyword used to define an abstract class is "abstract." An abstract class serves as a blueprint for other classes. It can contain abstract methods—methods without a body—that must be implemented by subclasses. Additionally, an abstract class can have fully implemented methods, which can provide some default behavior.

By marking a class as abstract, you signal that the class cannot be instantiated directly. Only subclasses that extend the abstract class can be instantiated, and they are required to provide implementations for any abstract methods declared in the superclass. This concept is fundamental in enforcing a contract for subclasses while allowing for code reuse and polymorphism.

The other keywords mentioned serve different purposes: "virtual" is not a keyword in Java (it is used in languages like C#), "class" is used to define a regular class, and "interface" is used to define a contract for classes to implement, which doesn't allow for any method implementations on its own. Thus, "abstract" is the correct choice for defining an abstract class in Java.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy