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 |
how to swap the variables without using temp and operators
Which language is pure oop?
What is encapsulation in simple terms?
what is the drawback of classical methods in oops?
What is polymorphism programming?
What is encapsulation in ict?
What causes polymorphism?
Objective The objective of this problem is to test the understanding of Object-Oriented Programming (OOP) concepts, in particular, on encapsulation. Problem Description Create a program for managing customer’s bank accounts. A bank customer can do the following operations: 1. Create a new bank account with an initial balance. 2. Deposit money into his/her account. 3. Withdraw money from his/her account. For this operation, you need to output “Transaction successful” if the intended amount of money can be withdrawn, otherwise output “Transaction unsuccessful” and no money will be withdrawn from his/her account. Input The input contains several operations and is terminated by “0”. The operations will be “Create name amount”, “Deposit name amount”, or “Withdraw name amount”, where name is the customer’s name and amount is an integer indicating the amount of money. There will be at most 100 bank accounts and they are all created on the first month when the bank is opening. You may assume that all account holders have unique names and the names consist of only a single word. Output The output contains the transaction result of withdrawal operations and the final balance of all customers after some withdrawal and deposit operations (same order as the input). Sample Input Create Billy 2500 Create Charlie 1000 Create John 100 Withdraw Charlie 500 Deposit John 899 Withdraw Charlie 1000 0
Can we have inheritance without polymorphism?
What is virtual constructors/destructors?
what is new modifier in C#
Can we define a class within the interface?