CoolInterview.com - World's Largest Collection of Interview Questions & Answers, FAQs, queries, sample papers, exam papers, dumps, what, why, how, where, when questions
Interview Success Kit - Get Success in Job Interviews Interview Success Kit - 30,000 Interview Que. & Ans.
Covers 30,000+ Interview Questions asked in actual MNC Interviews - all with model answers.

Sponsored Links

Interview Questions
Our Services

INTERVIEW QUESTIONS MICROSOFT C# DETAILS
Question :
What does the keyword virtual mean in the method definition?


Category C# Interview Questions
Rating (4.2) By 58 users
Added on 7/28/2011
Views 2557
Rate it!


Answers:

Source: CoolInterview.com

If a base class have a virtual method it means that method must be override by the derived class using override keyword.

Source: CoolInterview.com



Source: CoolInterview.com

A virtual function is a member function of a class, whose functionality can be over-ridden in its derived classes
or its called do nothing function .
Source: CoolInterview.com



Posted by: Ajay Verma

Contact Ajay Verma Contact Ajay Verma

Source: CoolInterview.com

virtual keyword is used in the base class method
when derived class use virtual method we use override key with derived class method and the implementation of method can be changed but not affecting the type signature of base class.

eg: base class
public virtual method1()
{
int a,b,c;
c=a+b;
Console.WriteLine(c);
}

derived class

public override method1()
{
int a,b,c;
c=a*b;
Console.WriteLine(c);
}



Source: CoolInterview.com



Posted by: ranjeeth

Contact ranjeeth Contact ranjeeth

Source: CoolInterview.com

virtual meathod is define in base class and which is over-ridden in child class..
base:class
public virtual method1()
{
string c="virtual method1"
Console.WriteLine(c);
}

derived class

public override method1()
{
string c="override meathod"
Console.WriteLine(c);
}
Source: CoolInterview.com



Posted by: rahil mohd

Contact rahil mohd Contact rahil mohd

Source: CoolInterview.com

If a Method is declared as Virutval in Base class then you can override the Method in derived Class by using Override keyword.

class Program
{
static void Main(string[] args)
{
CA a;
a= new CB();
a.Foo();
}

}
class CA
{
public virtual void Foo()
{
Console.WriteLine("Foo in parent Class");
}
}
class CB : CA
{

public override void Foo()
{
Console.WriteLine("Foo in Child Class");
}
}
Source: CoolInterview.com



Posted by: Nageswara Rao

Contact Nageswara Rao Contact Nageswara Rao

Source: CoolInterview.com

Basically virtual method has drastical affect on performance of application. No Doubt we can do all the things without virtual function but if we use Virtual then we have following benefits.

1. Same of name of function can be used in derived class after overriding and can change its body there but with same signature

2. Overrided function will point to same memory location that is of the virtual function. means same memory location can be shared.

Source: CoolInterview.com



Posted by: Gurpreet Singh

Contact Gurpreet Singh Contact Gurpreet Singh

Source: CoolInterview.com

A method declared as virtual in the base class can be implemented in the derived class with override keyword. But it is not a must. If we use new keyword it hides the method
Source: CoolInterview.com



Posted by: Titty Louis

Contact Titty Louis Contact Titty Louis

If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-

  • There should not be any Spelling Mistakes.
  • There should not be any Gramatical Errors.
  • Answers must not contain any bad words.
  • Answers should not be the repeat of same answer, already approved.
  • Answer should be complete in itself.
  • Name :*
    Email Id :*
    Answer :*
    Verification Code Code Image - Please contact webmaster if you have problems seeing this image code Not readable? Load New Code
    Process Verification Enter the above shown code: *
    Inform me about updated answers to this question

    Related Questions
    View Answer
    How's method overriding different from overloading?

    View Answer
    What's the top .NET class that everything is derived from?

    View Answer
    Describe the accessibility modifier protected internal.

    View Answer
    Are private class-level variables inherited?

    View Answer
    When you inherit a protected class-level variable? Who is it available to?

    View Answer
    Does C# support multiple inheritance?

    View Answer
    How do you inherit from a class in C#?

    View Answer
    What's the implicit name of the parameter that gets passed into the class' set method?

    View Answer
    Is it mandatory to implement all the methods which are there in abstract class if we inherit that abstract class..?

    View Answer


    What is the difference between const and static read-only?



    View Answer
    How to fill datalist usinf XML file and how to bind it,code behind language is c#

    View Answer
    WHAT IS THE ADVANTAGE OF SERIALIZATION?

    View Answer
    How we hand sql exceptions? What is the class that handles SqlServer exceptions?

    View Answer
    What is indexer? where it is used plz explain

    View Answer
    can we inherit the java class in C# class,how?

    View Answer
    We declare an integer variable 'x' in C# as

    View Answer
    A code block in C# is enclosed between

    View Answer
    To read user input from the console, the following statement is used

    View Answer
    The following is a correct call to the Main() function

    View Answer
    All the C# programs must have the following statement

    View Answer

    Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.

    View ALL C# Interview Questions & Answers

    User Options
    India News Network

    Latest 20 Questions
    The proprietor of a business is treated as a creditor for capital introduced by him, according to:- a) Money Measurement Concept b) Cost Concept c) Entity Concept d) Dual Aspect Concept
    State the losses from which Insurance Claims can be made?
    What is the meaning of Insurance Claims?
    If owner's equity of a business are Rs.90,000 and profits are of Rs. 60,000 for the year calculate total assets of the business:- a) Rs. 1,50,000 b) Rs. 1,20,000 c) Rs. 30,000 d) Rs. 1,70,000
    What is Yield to Maturity in Futures and Options Trading Market?
    What is Yield Curve in Futures and Options Trading Market?
    Who is a Writer in Futures and Options Trading Market?
    What is Wire House in Futures and Options Trading Market?
    What is Warehouse Receipt in Futures and Options Trading Market?
    What is Vertical Spread in Futures and Options Trading Market?
    What is Variable Limit in Futures and Options Trading Market?
    What is Underlying Security in Futures and Options Trading Market?
    What is Underlying Futures Contract in Futures and Options Trading Market?
    What is Uncovered put writing in Futures and Options Trading Market?
    What is Uncovered call writing in Futures and Options Trading Market?
    What is U.S. Treasury Note in Futures and Options Trading Market?
    What is U.S. Treasury Bond in Futures and Options Trading Market?
    What is U.S. Treasury Bill in Futures and Options Trading Market?
    What is Type in Futures and Options Trading Market?
    What is Trade Balance in Futures and Options Trading Market?



    Fresher Jobs | Experienced Jobs | Government Jobs | Walkin Jobs | Company Profiles | Interview Questions | Placement Papers | Companies In India | Consultants In India | Colleges In India | Exams In India | Latest Results | Notifications In India | Call Centers In India | Training Institutes In India | Job Communities In India | Courses In India | Jobs by Keyskills | Jobs by Functional Areas

    Testing Articles | Testing Books | Testing Certifications | Testing FAQs | Testing Downloads | Testing Interview Questions | Testing Jobs | Testing Training Institutes

    Gate Articles | Gate Books | Gate Colleges | Gate Downloads | Gate Faqs | Gate Jobs | Gate News | Gate Sample Papers | Gate Training Institutes

    MBA Articles | MBA Books | MBA Case Studies | MBA Business Schools | MBA Current Affairs | MBA Downloads | MBA Events | MBA Notifications | MBA FAQs | MBA Jobs
    MBA Job Consultants | MBA News | MBA Results | MBA Courses | MBA Sample Papers | MBA Interview Questions | MBA Training Institutes

    GRE Articles | GRE Books | GRE Colleges | GRE Downloads | GRE Events | GRE FAQs | GRE News | GRE Training Institutes | GRE Sample Papers

    IAS Articles | IAS Books | IAS Current Affairs | IAS Downloads | IAS Events | IAS FAQs | IAS News | IAS Notifications | IAS UPSC Jobs | IAS Previous Question Papers
    IAS Results | IAS Sample Papers | IAS Interview Questions | IAS Training Institutes | IAS Toppers Interview

    SAP Articles | SAP Books | SAP Certifications | SAP Companies | SAP Study Materials | SAP Events | SAP FAQs | SAP Jobs | SAP Job Consultants
    SAP Links | SAP News | SAP Sample Papers | SAP Interview Questions | SAP Training Institutes |




    Copyright ©2003-2016 CoolInterview.com, All Rights Reserved.
    Privacy Policy | Terms and Conditions



    Cache = 0 Seconds