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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T08:47:56+00:00 2026-06-16T08:47:56+00:00

In the java example below, can anyone explain exactly why the output of the

  • 0

In the java example below, can anyone explain exactly why the output of the program is “Orange” ? (this is an interview question)

public class Finder {
  public static void main(String[] args){
    System.out.println(X.Y.Z);
  }
}

class X {
  static W Y = new W();
  static class Y {
    static String Z ="Apple";
  }
}

class W {
  String Z = "Orange";
}
  • 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-16T08:47:57+00:00Added an answer on June 16, 2026 at 8:47 am

    The variable Y obscures the type Y. See the JLS:

    6.4.2. Obscuring

    A simple name may occur in contexts where it may potentially be
    interpreted as the name of a variable, a type, or a package. In these
    situations, the rules of §6.5 specify that a variable will be chosen
    in preference to a type, and that a type will be chosen in preference
    to a package. Thus, it is may sometimes be impossible to refer to a
    visible type or package declaration via its simple name. We say that
    such a declaration is obscured.

    The qualified name X.Y.Z is resolved according to:

    6.5.2. Reclassification of Contextually Ambiguous Names

    …

    If the name to the left of the "." is reclassified as a TypeName, then:

    • If the Identifier is the name of a method or field of the type denoted by TypeName, this AmbiguousName is reclassified as an ExpressionName.

    • Otherwise, if the Identifier is the name of a member type of the type denoted by TypeName, this AmbiguousName is reclassified as a TypeName.

    • Otherwise, a compile-time error occurs.

    This is unlikely to occur in practice because of the normal naming conventions for types and variables.

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

Sidebar

Related Questions

Can anyone point me to a code example (java preferably) or psuedocode that uses
For example I have a file name call A.java. Here its structure: public class
Take the PriorityQueue for example http://java.sun.com/j2se/1.5.0/docs/api/java/util/PriorityQueue.html#offer(E) Can anyone give me an example of a
Blow is a example copied from Think in Java 4 edition public class Rethrowing
Anyone can explain why calling [:].class on a map return null while calling [:].getClass()
i got a class call ClientIdBandwidth.java as shown at below public class ClientIdBandwidth {
For example, I have the java code below: URL u = new URL(http://google.com); URLConnection
The code is also at https://github.com/timp21337/java-generics-example package a; import java.util.List; public interface Container<T> {
Can anyone post or point me in the direction of a clear example of
Today i was told to create tree data structure with the below class, public

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.