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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:35:26+00:00 2026-05-22T23:35:26+00:00

My understanding is that it is possible to Override a method (marked as Virtual

  • 0

My understanding is that it is possible to Override a method (marked as Virtual) in a base class from a derived class using the keywords override.

But what about overriding a method in the same class?

In my specific case, I have a class x with 2 methods. Method a has some common behavior with b, and b adds functionality to method a.

In the past, I have duplicated the code of a in b and added the new functionality into b.

I would like to know if there is a better approach so I can centralize the behavior of method a.

    public class x
    {
       public static void a() {}
       public static void b() {}         
    }
  • 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-22T23:35:27+00:00Added an answer on May 22, 2026 at 11:35 pm

    You could simply call your method a() from within your method b(). No need (and no way) to override a method.

    public class x
    {
       private static int _i = 0;
    
       public static void a() {
           _i = 1;
       }
       public static void b() {
           a();
           // here is _i = 1;
       }         
    }
    

    On the other hand you could have parameter overloads for your method.

    public class x
    {
       private static int _i = 0;
    
       public static void a() {
           a(1);
       }
       public static void a(int i) {
          _i = t;
          // common code which can use _i
       }         
    }
    

    In this case you can call a(1) or a() with the same result.

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

Sidebar

Related Questions

It's possible that I'm not really understanding how git works here, but I have
Consider the example below: #include <iostream> using namespace std; class base { public: virtual
I'm not awfully knowledgeable about HTTP, but my understanding is that an HTTP request
It is my understanding that I can test that a method call will occur
It is to my understanding that one should use a forward-class declaration in the
It's my understanding that StackOverflow (SO) was built using ASP.NET. What surprised me is
After some research, it is my understanding that this is not possible. I can
When using TempData, my understanding is that it will keep whatever you put in
I read much about issues with onActivityResult , but it seems that none of
I'm looking to generate random similar colors using jquery. It is my understanding that

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.