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 7699399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:28:07+00:00 2026-05-31T22:28:07+00:00

How do I prevent a method from being overridden in a derived class? In

  • 0

How do I prevent a method from being overridden in a derived class?

In Java I could do this by using the final modifier on the method I wish to prevent from being overridden.

How do I achieve the same in C#?
I am aware of using sealed but apparently I can use it only with the override keyword?

class A
{
    public void methodA()
    {
        // Code.
    }

    public virtual void methodB()
    {
        // Code.
    }
}

class B : A
{
    sealed override public void methodB()
    {
        // Code.
    } 
}

So in the above example I can prevent the methodB() from being overridden by any classes deriving from class B, but how do I prevent class B from overriding the methodB() in the first place?

Update: I missed the virtual keyword in the methodB() declaration on class A when i posted this question. Corrected it.

  • 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-31T22:28:08+00:00Added an answer on May 31, 2026 at 10:28 pm

    You don’t need to do anything. The virtual modifier specifies that a method can be overridden. Omitting it means that the method is ‘final’.

    Specifically, a method must be virtual, abstract, or override for it to be overridden.

    Using the new keyword will allow the base class method to be hidden, but it will still not override it i.e. when you call A.methodB() you will get the base class version, but if you call B.methodB() you will get the new version.

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

Sidebar

Related Questions

Is it possible to prevent a public method from being overwritten in the child
Using SqlParameters is a recommended method to prevent SQL Injection in your database queries.
I was wondering if they was a way to prevent some commands from being
I want to use the RequireHttpsAttribute to prevent unsecured HTTP requests from being sent
I'd like to prevent my window from being updated until I finish receiving data
What is the best method of hiding php errors from being displayed on the
Is there any way to prevent Ruby's JSON.pretty_generate() method from escaping a Unicode character?
So I am trying to prevent the user from being able to use the
I'm trying to prevent output cached page from being ejected from my asp.net output
Is there a way to prevent a page from being cached based on some

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.