0 votes
158 views
in Theory by (245 points)
edited
explain any 8 characteristics of virtual function std 12th

1 Answer

0 votes
by (98.9k points)
selected by
 
Best answer

In C++, a virtual function is a member function of a class that is declared as virtual in its base class and is overridden in its derived classes. Here are eight characteristics of virtual functions:

  1. Virtual functions allow for dynamic binding: When a virtual function is called through a pointer or reference to a base class, the correct function implementation is determined at runtime based on the type of the object it points to.

  2. A virtual function is declared in a base class and can be overridden in any derived class.

  3. Virtual functions are implemented using a virtual function table or vtable that contains pointers to the derived class implementations of the virtual function.

  4. A class with at least one virtual function is considered a polymorphic class.

  5. Non-virtual functions are resolved at compile-time, whereas virtual functions are resolved at runtime.

  6. Virtual functions are usually declared in the public section of a class.

  7. Virtual functions can have a default implementation in the base class.

  8. Virtual destructors are necessary when dealing with polymorphic classes to ensure proper destruction of derived class objects.

Related questions

0 votes
0 answers 89 views
0 votes
1 answer 110 views
asked Mar 26, 2023 in Theory by Riya 1 (115 points)
0 votes
2 answers 228 views
asked Jul 20, 2022 in English by Doubtly (98.9k points)
0 votes
2 answers 380 views
0 votes
1 answer 143 views
0 votes
1 answer 243 views

Doubtly is an online community for engineering students, offering:

  • Free viva questions PDFs
  • Previous year question papers (PYQs)
  • Academic doubt solutions
  • Expert-guided solutions

Get the pro version for free by logging in!

5.7k questions

5.1k answers

108 comments

559 users

...