what is virtual function in c++

Answers were Sorted based on User's Feedback



what is virtual function in c++..

Answer / achal

the concept of vitual function comes when inheritance is at
work. If the overriden function is not made virtual in base
class , then pointer of derived class will call the funtion
in base class(instead it should have called the one from
derived class.)
this is why we make the function in base as virtual.

Is This Answer Correct ?    37 Yes 6 No

what is virtual function in c++..

Answer / sree

virtual function comes into picture while inheriting the
base class functions to the derived class functions.
ifthe virtual isnot used then the pointer of derived class
points to the baseclass function

Is This Answer Correct ?    28 Yes 1 No

what is virtual function in c++..

Answer / indu

IT'S OVERRIDING A BASE CLASS DEFINITION AT RUN TIME.MEMBER
FUNCTION IN BASE CLASS AND DERIVED CLASS IS SAME. NORMALLY
IT INVOKE THE BASE CLASS DEFINITION IF BOTH FUNCTION NAME
IS SAME.BUT WE NEED TO ACCESS THE DERIVED CLASS DEFINITION
WE GO FOR VIRTUAL FUNCTION

Is This Answer Correct ?    20 Yes 3 No

what is virtual function in c++..

Answer / b.balaganesan

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.

Need for Virtual Function:

The vital reason for having a virtual function is to
implement a different functionality in the derived class.

For example: a Make function in a class Vehicle may have to
make a Vehicle with red color. A class called FourWheeler,
derived or inherited from Vehicle, may have to use a blue
background and 4 tires as wheels. For this scenario, the
Make function for FourWheeler should now have a different
functionality from the one at the class called Vehicle.
This concept is called Virtual Function.

Is This Answer Correct ?    10 Yes 3 No

what is virtual function in c++..

Answer / hemin_sdek@yahoo.com

IT'S OVERRIDING A BASE CLASS DEFINITION AT RUN TIME.MEMBER
FUNCTION IN BASE CLASS AND DERIVED CLASS IS SAME. NORMALLY
IT INVOKE THE BASE CLASS DEFINITION IF BOTH FUNCTION NAME
IS SAME.BUT WE NEED TO ACCESS THE DERIVED CLASS DEFINITION
WE GO FOR VIRTUAL FUNCTION

Is This Answer Correct ?    6 Yes 2 No

what is virtual function in c++..

Answer / guest

virtual funtion in cpp is define as globle acess in the
variable.

Is This Answer Correct ?    14 Yes 41 No

Post New Answer

More OOPS Interview Questions

Why it is called runtime polymorphism?

0 Answers  


What exactly is polymorphism?

0 Answers  


Why do while loop is used?

0 Answers  


What is a class?

32 Answers   Infosys, TCS, Thylak,


IS IT NECESSARY TO INITIALIZE VARIABLE? WHAT IF THE INSTANCE VARIABLE IS DECLARED final ? IS IT NECESSARY TO INITIALIZE THE final VARIABLE AT THE TIME OF THEIR DECLARATION?

0 Answers  






Can we override main method?

0 Answers  


what is runtime polymorphism? For the 5 marks.

3 Answers  


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

0 Answers  


create a class complex having real and imaginary part of a complex no. as a data member. overload the binary operators(+,- and *) to perform the operations on complex no. objects. overload binary operator using friend function.

2 Answers   CTS, Delhi University,


What is oops and its features?

0 Answers  


The IT giant Tirnop has recently crossed a head count of 150000 and earnings of $7 billion. As one of the forerunners in the technology front, Tirnop continues to lead the way in products and services in India. At Tirnop, all programmers are equal in every respect. They receive identical salaries and also write code at the same rate. Suppose 14 such programmers take 14 minutes to write 14 lines of code in total. How long will in take 5 programmers to write 5 lines of code in total ?

6 Answers   TCS,


difference between abstraction and encapsulation with progarammatic eg. hi,just recently i went for an interview .The interviewer asked what is the difference between abstraction and encapsulation with programmatic eg. I gave the answer as encapsulation mean hiding the relevant data which is not useful for the user, eg a electric fan .hiding the information how the electricity is converted into machanical energy. abtraction showing only the relevant data to the user eg electric fan. it look ,its color ,it design etc only relevant data. Then the interviewer asked me, give me some programmic eg .I Said Let assume a web form having control like textbox,button etc. The user can view textbox,button etc this is the eg of abstraction and when the user click on the button how he is redirected is not known by the user is the eg of the encapsulation. Am I Correct .was the answer given by me is perfect .now i am planing to go for an another interview should i give the same answer.IF not please suggest me a better answer.with some good eg Please help

1 Answers  


Categories