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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:38:51+00:00 2026-05-28T03:38:51+00:00

Given a few classes/interfaces. public interface A { public int doSomthing(int x); } public

  • 0

Given a few classes/interfaces.

public interface A {
    public int doSomthing(int x);
}

public class B implements A {
    int doSomthing(int x){
        //actually do something
    };
}

public class C extends B {
    //does some specific implementations of what B does
    // but does NOT override "int doSomething(int)"
}

How in a code using implementation C (or any subClass of C) may I determine (programatically) that B was the class implementing int doSomething(int).

Or if any of B’s subclasses (lets say D which extends C) overrid “int doSomething(int)” how, when working with E (which extends D, yeah … this is one large family of classes) may I define first parent that implemented “int doSomething(int)” ?

Thank you all in advance 🙂

  • 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-28T03:38:52+00:00Added an answer on May 28, 2026 at 3:38 am

    You can do that using reflection, i.e. you start at the class the object has and check whether that class defines the method which is identified by the methodname and parameter types. If the class doesn’t define that method you get its super class and check this, until you hit Object in which case the method isn’t available at all.

    For public methods, it’s easier since Java has already a built-in method for this:

    Class<?> mostSpecificImplementor = 
      yourObject.getClass().getMethod( "doSomthing", int.class ).getDeclaringClass();
    

    Note that this only works for public methods, otherwise you’d have to search up the class hierarchy yourself (use getDeclaredMethod(...) in this case).

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

Sidebar

Related Questions

Given the following classes: public class ContentItem : IEquatable<ContentItem> { ... } and public
I am just studying a few classes given to me by my lecturer and
Given a list of classes inheriting from this base: class Plugin(object): run_after_plugins = ()
Given software where ... The system consists of a few subsystems Each subsystem consists
This are few of the fundamental database questions which has always given me trouble.
Could somebody please name a few. I could given time, but this is for
A basic definition and example and a few references for X-Macros is given in
This is not a technical question, but given that there are a few iPhone
What if I have few factory methods returning non-public type and pairing set of
I've worked/seen a few spring-hibernate web application projects having as many interfaces as there

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.