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

  • Home
  • SEARCH
  • 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 4591868
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:27:25+00:00 2026-05-21T22:27:25+00:00

Does super has higher priority than outer class? Consider we have three classes: ClassA

  • 0

Does super has higher priority than outer class?

Consider we have three classes:

  1. ClassA
  2. ClassB
  3. Anonymous class in ClassB that extends ClassA

ClassA.java:

public class ClassA {
    protected String var = "A Var";

    public void foo() {
        System.out.println("A foo()");
    }
}

ClassB.java:

public class ClassB {
    private String var = "B Var";

    public void test() {

        new ClassA() {
            public void test() {
                foo();
                System.out.println(var);
            }
        }.test();
    }

    public void foo() {
        System.out.println("B foo()");
    }
}

When I call new ClassB().test(), I get the following output (which is pretty much expected):

A foo()
A Var

Question: Is it defined somewhere that inner class takes (methods and members) first from the super class and then from the outer class or is it JVM compiler implementation dependent? I have looked over the JLS(§15.12.3) but couldn’t find any reference for that, maybe it is pointed out there but I misunderstood some of the terms?

  • 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-21T22:27:26+00:00Added an answer on May 21, 2026 at 10:27 pm

    See 6.3.1 Shadowing Declarations:

    A declaration d of a method named n shadows the declarations of any other methods named n that are in an enclosing scope at the point where d occurs throughout the scope of d.

    Which may be interpreted as “the declaration of foo (inherited from ClassA) shadows the declaration of any other methods named foo that are in an enclosing scope (ClassB) at the point where foo occurs, throughout the scope of foo.”

    Also relevant – section 15.12.1:

    15.12.1 Compile-Time Step 1: Determine Class or Interface to Search

    The first step in processing a method invocation at compile time is to figure out the name of the method to be invoked and which class or interface to check for definitions of methods of that name. There are several cases to consider, depending on the form that precedes the left parenthesis, as follows:

    • If the form is MethodName, then there are three subcases:
      • If it is a simple name, that is, just an Identifier, then the name of the method is the Identifier. If the Identifier appears within the scope (§6.3) of a visible method declaration with that name, then there must be an enclosing type declaration of which that method is a member. Let T be the innermost such type declaration. The class or interface to search is T.
      • If it is a qualified name of the form TypeName.Identifier, then […]
      • In all other cases, the qualified name has the form FieldName.Identifier; then […]
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How does super() work with multiple inheritance? For example, given: class First(object): def __init__(self):
Background I have a MacAlly IceKey keyboard. This keyboard has volume buttons that require
I have three quick questions I've seen conflicting answers to that hopefully someone can
I have written an android app which listens to the phone signal strength using
I have read posts like these: What is a metaclass in Python? What are
I'm creating a class that inherits from a parent class with protected instantiation. The
Suppose you have legacy java code which can not be compiled by an up-to-date
I have a board as a canvas with several shapes drawn on it, some
So, I'm looking through a java library (JScience) after someone here thoughfully pointed me
I cant understand what this warning I get on Xcode is about. Searching for

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.