Which keyword is used to define a method that can be overridden in derived classes?

Prepare for the Avaloq Script Exam with flashcards and multiple choice questions, each with detailed explanations and hints. Boost your proficiency and ensure exam success!

The keyword that is used to define a method that can be overridden in derived classes is "virtual." When a method is marked as virtual in a base class, it indicates that this method can be redefined or overridden in any derived class that inherits from the base class. This is a fundamental aspect of polymorphism in object-oriented programming, allowing a derived class to provide its own implementation of the method that extends or modifies the behavior defined in the base class.

By using the virtual keyword, the base class establishes an expectation that its method may be altered, promoting flexible and maintainable code. This allows for dynamic method resolution at runtime, which enables the appropriate method from the derived class to be executed when an instance of the derived class is called.

The other options do not fulfill the same role. The "override" keyword is used in derived classes to explicitly specify that a method is overriding a virtual method from a base class, but it does not define a method itself. "Inherit" is not a keyword in this context and doesn't pertain directly to method overriding, while "abstract" defines a method that must be implemented by derived classes, but it doesn’t allow for the same flexible overriding as a virtual method does. Abstract methods cannot be instantiated directly

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy