what is virtual function?
Answers were Sorted based on User's Feedback
Answer / purba phalguni mishra, gandhi
The objects of the polymorphic class, addressed by
pointers, change at runtime and respond differently for the
same message.Such mechanism requres postponment of binding
of a function call to the member function [ VIRTUAL] untill
runtime.
Is This Answer Correct ? | 15 Yes | 9 No |
Answer / varun sir
a virtual function is used to avoid duplicacy in derived
classes. suppose that there is a base class which has two
properties a and b. now suppose that two derived classes
named 'der1' and 'der2' are deriving from that base class,
then both properties a and b of base class will be
inherited to both of the derived classes. now if a new
class is derived from 'der1' and 'der2' then both of the
properties a and b of 'der1' and 'der2' will also be
inherited into newly derived class. this will cause
duplicacy in newly obtained derived class. so in order to
avoid this duplicacy , we use virtual functions.
Is This Answer Correct ? | 8 Yes | 6 No |
Answer / pooja pimplapure
Virtual, as the name implies, is something that exists in
effect but not in reality. The concept of virtual function
is the same as a function, but it does not really exist
although it appears in needed places in a program. The
object-oriented programming language C++ implements the
concept of virtual function as a simple member function,
like all member functions of the class.
The functionality of virtual functions can be over-ridden
in its derived classes. The programmer must pay attention
not to confuse this concept with function overloading.
Function overloading is a different concept and will be
explained in later sections of this tutorial. Virtual
function is a mechanism to implement the concept of
polymorphism (the ability to give different meanings to one
function).
Is This Answer Correct ? | 4 Yes | 2 No |
Answer / b.mamatha
A virtual function or virtual method is a function or method
whose behaviour can be overridden within an inheriting class
by a function with the same signature. This concept is a
very important part of the polymorphism portion of
object-oriented programming (OOP).
Is This Answer Correct ? | 2 Yes | 0 No |
Answer / diwakar saraswat
virtual function is a member function of the class.
virtual function declare with virtual keyword.
once virtual function declare in base class, we can define
this function in drive class.
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / bhupendra more
A function qualified by the virtual keyword. When a virtual
is called via a pointer,the class of the object pointed to
determine which function definition will be used. Virtual
function implement polymorphism. whereby objects belonging
to different classes can respond to the same massage in
different way.
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / vindhyachal kumar gupta
C++ virtual function is a member function of a class, whose
functionality can be over-ridden in its derived classes. The
whole function body can be replaced with a new set of
implementation in the derived class. The concept of c++
virtual functions is different from C++ Function overloading.
C++ Virtual Function - Properties:
C++ virtual function is,
* A member function of a class
* Declared with virtual keyword
* Usually has a different functionality in the derived class
* A function call is resolved at run-time
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / ann
A virtual function is a function which is preceded by the
keyword 'virtual' followed by its normal declaration.When we
use the same function name in both the base and derived
classes,the function in base class is declared as virtual.
This concept is a very important part of the
polymorphism portion of object-oriented programming
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / chandan jena
To make a class polymorphic we use virtual function.It
provides runtime polymorphism.
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / dev malhotra
virtual function is defined as virtual is a keyword which is used when one function or method is used in both base class and drived class at a time then, during compile time compiler cannot distinguish that which one compile or run first.
then to distinguish that problem the programmer use special keyword in base class or in derived class that is known as "VIRTUAL" keyword.
Due to this keyword the compiler always compiles the assigned virtual keyword method or function and this is called as virtual function.
Is This Answer Correct ? | 0 Yes | 0 No |
What are main features of oop?
what is virtual function in c++
c++ is a pure object oriented programming or not?
What is multilevel inheritance?
what is the use of mutable key word
What is object in oop with example?
What is encapsulation c#?
#include <stdio.h> #include <alloc.h> #include <stdlib.h> #include <conio.h> void insert(struct btreenode **, int); void inorder(struct btreenode *); struct btreenode { struct btreenode *leftchild; struct btreenode *rightchild; int data; }; main() { struct btreenode *bt; bt=(struct btreenode *)NULL; int req,i=1,num; clrscr(); printf("Enter number of nodes"); scanf("%d",&req); while(i<=req) { printf("Enter element"); scanf("%d",&num); insert(&bt,num); i++; } inorder(bt); } void insert(struct btreenode **sr, int num) { if(*sr==NULL) { *sr=(struct btreenode *)malloc (sizeof(struct btreenode)); (*sr)->leftchild=(struct btreenode *)NULL; (*sr)->rightchild=(struct btreenode *)NULL; (*sr)->data=num; return; } else { if(num < (*sr)->data) insert(&(*sr)->leftchild,num); else insert(&(*sr)->rightchild,num); } return; } void inorder(struct btreenode *sr) { if(sr!=(struct btreenode *)NULL) { inorder(sr->leftchild); printf("\n %d",sr->data); inorder(sr->rightchild); } else return; } please Modify the given program and add two methods for post order and pre order traversals.
what is diff between .net 1.1 and .net 2.0
Templates mean
pointers are support in C#? if yes then how to use it?
8 Answers Softvision Solution,
What is DeadlyDiamondDeathProblem ?