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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:26:24+00:00 2026-05-27T20:26:24+00:00

This is probably a bad thing to do, as discussed in Can parent and

  • 0

This is probably a bad thing to do, as discussed in Can parent and child class in Java have same instance variable?. (What if the parent variable name is changed? Then it will not be shadowed anymore.) However, I am still curious whether variables that are differently static/nonstatic will shadow each other. On one hand I would expect they are the same variable name so would be shadowed, but on the other hand it seems like the compiler might distinguish between the two based on staticness.

  • 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-27T20:26:25+00:00Added an answer on May 27, 2026 at 8:26 pm

    From The Java Language Specification:

    If an expression name consists of a single Identifier, then there
    must be exactly one visible declaration denoting either a local
    variable, parameter or field in scope at the point at which the the
    Identifier occurs. Otherwise, a compile-time error occurs.

    If the declaration declares a final field, the meaning of the name is
    the value of that field. Otherwise, the meaning of the expression name
    is the variable declared by the declaration.

    If a method in a superclass refers to a particular field (static or otherwise) of that class, only that class’s declaration of the field will be in scope at that point; any fields (static or otherwise) of subclasses will not be in scope. Therefore, the method will always use the superclass field, even if a subclass inherits it and shadows that field.

    This answer is completely rewritten based on my new understanding of the question. Below is my first answer, kept for posterity.

    From The Java Language Specification:

    A declaration d of a field, local variable, method parameter,
    constructor parameter or exception handler parameter named n shadows
    the declarations of any other fields, local variables, method
    parameters, constructor parameters or exception handler parameters
    named n that are in scope at the point where d occurs throughout the
    scope of d.

    This suggests that compilers are required to shadow parent variables, regardless of staticness.

    Note that none of this is relevant to inherited methods, which always use the original variables regardless of whether a subclass shadows them. I suspect this isn’t what you meant to ask.

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

Sidebar

Related Questions

Ok, so this seems bad (and it probably is, but i have enough doubts
This probably has a simple answer, but I must not have had enough coffee
This probably sounds really stupid but I have noo idea how to implement jquery's
OK, this probably is supposed to be the easiest thing in the world, but
I've been working all day and I somehow can't get this probably easy task
Say we have this hyper simple class hierchy: public class SomeMath { public int
This thing is troubling me for a while now. I have asked questions before,
This is a picky thing and it is probably just my OCD flairing up
This probably sounds like a terrible idea at first glance, but here is my
I know this probably really simple but Im not sure what im doing wrong...

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.