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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:22:32+00:00 2026-06-04T12:22:32+00:00

I have hierarchy of classes: class A{} class B: A {} class C:B {}

  • 0

I have hierarchy of classes:

class A{}
class B: A {}
class C:B {}

is it possible to implement method in class A and it would be inherited by derived classes B and C and so on and that method should return value of class type?

A val = A.method(); (val is A)
B val = B.method(); (val is B)
C val = C.method(); (val is C)

And I don’t want use of generics in call of this method, ie:

C val = C.method<C>();

Guys, excuse me, one elaboration, this method should be static.

I don’t want to use generic in method istelf, because it forces to point type that method should return, whereas method should return type of its class.

class A
    {
      Method<T>()
      {
         T result;
         return result;
      }
    }

If I have such method I can change return type:

D result = A.Method<D>();

but I wanted it to return value of type A;

  • 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-06-04T12:22:34+00:00Added an answer on June 4, 2026 at 12:22 pm

    No, that is not possible.

    To call the method like that it would have to be static, and static methods are not inherited.

    Using B.method() to call a static method in A is the same as using A.method(). The compiler just uses the type to determine where the method is, but it’s impossible for the method to know if it was called using the A or B type.

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

Sidebar

Related Questions

I have an hierarchy of classes that looks like the following: class Critical {
I have a small hierarchy of classes that all implement a common interface. Each
Let's say we already have a hierarchy of classes, e.g. class Shape { virtual
I have a quite complex class hierarchy in which the classes are cross-like depending
I have an hierarchy of classes that I fetch from database by LINQ to
I have a hierarchy of classes that are serialised to XML using XMLSerialiser .
I have a hierarchy of objects define as follows: class Request { RequestType type
I have a hierarchy of objects that I would like to show using a
I have the following hierarchy of classes class classOne { virtual void abstractMethod() =
Say, I have such classes hierarchy: public interface IRepository { } public class SomeSimpleRepository

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.