Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
In an inheritance relationship, which one of the following methods is most likely to be virtual?

a) Constructor

b)Destructor

c) Copy Constructor

d) None of the above
Posted
Updated 31-May-10 1:23am
v4

laxman2jasmi wrote:
which one of the following methods is most likely to be virtual?


No method is there in your question
 
Share this answer
 
Comments
laxman2jasmi 21-Sep-10 3:06am    
Reason for my vote of 5
Automatic vote of 5 for accepting answer.
laxman2jasmi wrote:
In an inheritance relationship, which one of the following methods is most likely to be virtual?

The first one.
:-D
 
Share this answer
 
Comments
laxman2jasmi 21-Sep-10 3:06am    
Reason for my vote of 5
Automatic vote of 5 for accepting answer.
laxman2jasmi wrote:
In an inheritance relationship, which one of the following methods is most likely to be virtual?


when u have a function in your class which you want to be implemented by the inherited class you can use the virtual function, hers a code for demonstration

using System;
//base class
class parent
{
    //with a virtual function
    public virtual void myfunction()
    {
        Console.WriteLine("Hi i am virtual function");
    }
}

class child: parent
{
    //attempt to override the parent class function called myfunction
    public override void myfunction()
    {
        Console.WriteLine("I am Legend");
    }
//making another virtual function which is to be overriden
    public virtual void hellboy()
    {
        Console.WriteLine("My name is Hellboy");
    }
}
//now radix class inherits child which means child is the parent for radix, radix can override th parent class function too but i have not done this

class Radixx :child
{
    public override void hellboy()
    {
        Console.WriteLine("My name is Radix and i am a programmer");
    }
   
}

class implement
{
    public void cl(parent p)
    {
        //calling myfunction
        p.myfunction();
    }
    public void arsenal(Radixx rad)
    {
        //calling hellboy function
        rad.hellboy();
    }
}

class calling
{
    static void Main()
    {
        implement obj = new implement();
        child radix = new child();
        obj.cl(radix); //see the magic here 
        Radixx rdx = new Radixx();
        obj.arsenal(rdx); //Magic here too
       
    }
}


Do rate my answer once you find it useful

Thanks & Regards
Radix :rose:
 
Share this answer
 
Comments
Sandeep Mewara 21-May-10 10:06am    
Did you read the question properly? He didnt asked what you have replied!
laxman2jasmi 21-Sep-10 3:06am    
Reason for my vote of 5
Automatic vote of 5 for accepting answer.
The ones that are most likely to be overriden. This isn't always the case though, after all you may be using an abstract base class, so they may be abstract instead of virtual.
 
Share this answer
 
Comments
laxman2jasmi 21-Sep-10 3:06am    
Reason for my vote of 5
Automatic vote of 5 for accepting answer.
The first One. i.e. Constructor
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900