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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:06:42+00:00 2026-06-15T15:06:42+00:00

I have noticed following situation : Inner class is calling method which there is

  • 0

I have noticed following situation : Inner class is calling method which there is in super class of it and in outer class. Here the code:

 public class Main
    {

        class Inner extends InnerBase{
           public void callMethod(){
               method();
           }
        }

        void method(){
            System.out.println ("Called Main's method");
        }

        class InnerBase{
            void method(){
                System.out.println ("Called InnerBase's method");
            }
        }
    }

Now when callMethod() is calling it calls the method of super class and prints “Called InnerBase’s method”. If I am trying to ‘Open Declaration’ from IDE (Eclipse) on method() which is calling in callMethod(), then it goes to method in outer class. It is confusing which one is calling real. Can you suggest or provide some material which explain situation of choosing execution method with same name in outer class and in super class. Thank You 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-06-15T15:06:43+00:00Added an answer on June 15, 2026 at 3:06 pm

    By using a qualified this (JLS §15.8.4. Qualified this), you can specify without any doubt what the selected method will be.

    public void callMethod()
    {
        Main.this.method();
    }
    

    The rule is simple: it will always select the closest method.

    InnerBase.method() is part of it own methods. So that is closer than Main.method(), because Main.method() is part of another not-related class. If you had another method() in Inner, then it would select that method, because it is in the same class.

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

Sidebar

Related Questions

I have the following sample code and noticed that if I attempt to use
I have the following situation: I am using a third party .net library which
Ok, here is my situation, which has come to this... dramatic pause... I have
I have the following code in a non-browser environment (Titanium Studio) and I noticed
I have the following in my code: lblIsInvalid.Visible = True I have noticed that
I am using the embedded version of jetty. I have noticed the following: in
I have the following XML code. You will notice the tag Description is repeated,
I'm creating a custom preloader for a Flex app and have noticed the following
I have the following situation: I have an event handler, that displays small messages
I have an awkward situation in which I have a 32-bit lib that must

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.