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

  • Home
  • SEARCH
  • 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 6883055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:20:01+00:00 2026-05-27T05:20:01+00:00

Here is the scenario public class Connection { public virtual void close() { /*Some

  • 0

Here is the scenario

     public class Connection
     {
         public virtual void close()
         {
           /*Some code */
         }
     }

    public interface IHttpRelay
    {

         void close();

    }

    public class HttpConnection: Connection,IHttpRelay
    {
         public /*keyword*/ void close()
         {
            base.close();
         }
    }

    public class Http:HttpConnection
    {
         public override void close()
         {
           /*Some code */
         }
    }

My question is to know if i should declare the method close() in HttpConnection class with an override or virtual keyword since it overrides and is overridden at the same time.

  • 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-27T05:20:02+00:00Added an answer on May 27, 2026 at 5:20 am

    You need to mark it with override. If you mark it with virtual in HttpConnection, it will hide the base class implementation, not override it. As a result, it could not be used polymorphically. Mark one method virtual, the rest should simply be overrides.

    As a simple example

    class A
    {
        public virtual void Frob()
        {
            Console.WriteLine("A");
        }
    }
    
    class B : A
    {
        public virtual void Frob()
        {
            Console.WriteLine("B");
        }
    }
    
    class C : B
    {
        public override void Frob()
        {
            Console.WriteLine("C");
        }
    }
    

    Here, B redefines a virtual Frob, it does not override. It follows your example. However, when working with an instance of C through the reference of A, something “unexpected” happens.

    A obj = new C();
    obj.Frob(); // "A" is written to the screen, not "C"
    

    What is written to the screen is “A”, you did not get the polymorphic behavior you would expect. When you hide a member instead of override it, you only get the new behavior via the reference of the hiding class. When referenced through a base class, you receive the base behaviors! This is typically not what you desire in a virtual/override polymorphic scenario. If you replace the virtual with override in class B and then run the above snippet, the output is what you would expect.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the scenario... interface IBase{ void Process(int value); } abstract class Base : IBase
Here is a scenario class page { public $name; public $title; public function showhead()
Issue Seems like the condition gets ignored. Here is my scenario: Source class public
I will start by explaining my scenario in code: public class A { }
So here is the scenario, I am refactoring some spaghetti code. My first problem
Consider the following scenario: public class Entity1 { virtual public Int32 ID { get;
Here's the scenario. I'm debugging my own app (C/C++) which is using some library
Consider the following class structure: class Filter { virtual void filter() = 0; virtual
Lets say I have some view models set up as follows: public class User
I have a similar scenario as this one: public class TestLinq2Xml { private XElement

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.