About Virtual functions and their use ?

Answers were Sorted based on User's Feedback



About Virtual functions and their use ?..

Answer / sam

virtual function is used to overddin that function in
derived class

Is This Answer Correct ?    46 Yes 4 No

About Virtual functions and their use ?..

Answer / deepika

Second answer given here is correct to some extent.
If we use Virtual keywork next to a mehtod,it can be
overridden in derived classes,but it is not must to
override.

Is This Answer Correct ?    26 Yes 4 No

About Virtual functions and their use ?..

Answer / anand

If the instance function declared with a virtual modifier
then the function is called virtual function.

the derived class can give the redefinition to the virtual
function its optional.

Is This Answer Correct ?    26 Yes 7 No

About Virtual functions and their use ?..

Answer / sandeep

Virtual keyword is used to perform the dynamic binding
instead of early binding. To be brief below is the example

Class base
{
void display()
{
cout<<"in Base";
}
}
Class derived: public base
{
void display()
{
cout<<"in derived";
}
}
void main()
{
base* ptr;

ptr = new derived;
ptr->display();
}

When we execute above program output will be displayed as
"in base", but expected output was "in derived". So compiler
was choosing member function which matches the type of the
pointer rather than the member function which matches the
content of the pointer. But when we use Virtual keyword in
base class, it perform the dynamic binding, i.e., at run
time it choose the function to execute and executes "in
derived". So when we use virtual keyword, compiler will
select the member function which matches the content of the
pointer and it will ignore the member function which matches
the type of the pointer.

Is This Answer Correct ?    17 Yes 1 No

About Virtual functions and their use ?..

Answer / vishal sharma

Virtual Method are feature of object oriented programming
and used to Identify the Type of object that is calling any
particular method at the Run time so provides flexibility in
calling method.

Is This Answer Correct ?    17 Yes 2 No

About Virtual functions and their use ?..

Answer / tiger skumar

The Virtual is a keyword it used in the base class.When we
use the Virtual keyword in the function it must be override
in the inherited class with the same name.

Is This Answer Correct ?    35 Yes 21 No

About Virtual functions and their use ?..

Answer / vijay rana

when we override a metod in sub class,and we want to hide
the decelaration of the base class member then we used the
keyword virtual in superclass,
and keyword override in the subclass

Is This Answer Correct ?    15 Yes 3 No

About Virtual functions and their use ?..

Answer / deepak jindal

If a base class method is to be overriden, It is defined
using virtual keyword. You need to use the override keyword
in order to re-implement the virtual method. Exp:

public class Employee
{
public virtual void SetBasic(float money) //This method may
be overriden
{ Basic += money; }
}


public class Manager : Employee
{
public override void SetBasic(float money) //This method is
being overriden
{
float managerIncentive = 10000;
base.SetSalary(money + managerIncentive); //Calling base
class method
}
}

Is This Answer Correct ?    14 Yes 3 No

About Virtual functions and their use ?..

Answer / jyothish vakkom

intersection of 4 & 6

Is This Answer Correct ?    11 Yes 1 No

About Virtual functions and their use ?..

Answer / om shivaya namaha

Suppose we have 4 class

Class
Base (haveing method Display())
Class | Class
Parent1-------------------------------------------Parent2
(having method : Par1) (having method : Par2)
| |
-------------------------------------------------
|
Class Child( having Method :ch1)



as Parent1,Parent2 derived from the Base class the Method
Display will be inherited in both Parent Classes and the
Child class is inherited from parent1,parent2
so the Child class may contain Display(Base class Method)
method 2 time so it will create runtime problems to avoid
such problems we have to use Virtual Overide concepts


Class
Base (haveing method Virtual:Display())
Class | Class
Parent1-------------------------------------------Parent2
(having method : Par1) (having method : Par2)
Override : Display() Override : Display()
| |
-------------------------------------------------
|
Class Child( having Method :ch1)

then the Child class will contail only one Display method

Is This Answer Correct ?    9 Yes 2 No

Post New Answer

More C Sharp Interview Questions

What is difference between class and interface in c#?

0 Answers  


What is the use of ienumerable in c#?

0 Answers  


What is oledb in c#?

0 Answers  


Hi to everybody. Lastweek i had taken an interview on c#. They ask what is boxing & unboxing, Masking.Please tell the answer and it is useful for me.

8 Answers  


Can arraylist hold primitive types?

0 Answers  


To allow an element to be accessed using a unique key which .NET collection class is used ?

0 Answers   Siebel,


What’s difference between Association, Aggregation and Inheritance relationships?

2 Answers   TCS,


Integer at long type variable are not object.Support your answer with example.And explain the technique to convert from value type to reference type and vice-versa.

1 Answers   HCL,


What is a console operator?

0 Answers  


What is boolean method?

0 Answers  


1.write a program in C# to find a given point which is inside in a circle. Given circle's radius and its center point? 2.Write a program in C# to generated 20 prime numbers greater than a given number? (It should be more efficient for large numbers also) 3. Write a Code to check whether a given point is inside a circle or not? given Circle's raduis and its center point. 4. using oops concept, design an elevator do not forget buttons on each floor..

2 Answers  


Define a partial class?

0 Answers  


Categories