Type Here to Get Search Results !

What is the purpose of a "virtual" method in OOP?

0

 What is the purpose of a "virtual" method in OOP?

A) To prevent a method from being overridden.
B) To allow a method to be overridden in derived classes.
C) To define an interface.
D) To create a static method.

Answer: B) To allow a method to be overridden in derived classes.

Explanation: A virtual method is a method declared in a base class that can be overridden in derived classes. This allows for dynamic method resolution, where the method that gets executed is determined at runtime based on the actual object type, not the type of reference.

Post a Comment

0 Comments