Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6754563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:17:44+00:00 2026-05-26T13:17:44+00:00

I have been programming in C++ for sometime and now I am starting to

  • 0

I have been programming in C++ for sometime and now I am starting to work with C# but I cannot get the idea of virtual and override keywords. Since the pointers and all related to it’s stuff is mostly gone from C++ we do not really need them do we ? Or I am missing some major points of C# programming.

Example :

namespace ConsoleApplication1
{
    public class Employee
    {
        public virtual void GetPayCheck()
        {
            Console.WriteLine("employee gets his pay check ");
        }

        public void Work()
        {
            Console.WriteLine("employee works ");
        }
    }
    public class Manager : Employee
    {
        public override void GetPayCheck()
        {
            Console.WriteLine("MANAGER gets his pay check ");
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Employee emp = new Employee();
            Manager exec = new Manager();
            emp.Work();
            exec.Work();
            emp.GetPayCheck();
            exec.GetPayCheck();
        }
    }
}

Even if I omit virtual or override keywords ( or both ) I still get the same output.
What am I

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:17:44+00:00Added an answer on May 26, 2026 at 1:17 pm

    Using virtual and override allows you to completely replace the Work method, regardless of what type the variable is declared as. If a method is declared as virtual, the CLR checks if the object is a derived class and if the method has been overridden. If a method is not virtual, the CLR just calls the method with the name Work from the type that the object has been declared as.

        static void Main(string[] args)
        {
            Employee emp = new Employee();
            Manager exec = new Manager();
    
            DoWork(emp); // employee works and gets pay check
            DoWork(exec); // if virtual and override are used, MANAGER get pay check
                          // however, if you don't override the method, DoWork
                          // will treat the argument as an Employee.
        }
    
        static void DoWork(Employee emp)
        {
            emp.Work();
            emp.GetPayCheck();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have been programming for sometime but all of my programming books have not
I have been programming in Java since 2004, mostly enterprise and web applications. But
I have been programming since 1999 for work and fun. I want to learn
Since I have been mostly using script languages in the past time but now
I have been programming in Perl, off and on, for years now, although only
I have been using Emacs since version 18. Emacs Lisp isn't my routine programming
I have been programming with .NET 2.0 version for quite sometime and would like
I have been programming in Smalltalk for some time, but I never really needed
I have been programming on iPhone for quite sometime and have had bad experiences
Since some time ago I have been programming in php with oracle, and I've

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.