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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:06:11+00:00 2026-06-13T11:06:11+00:00

Lets say we have these packages and classes: package p1; public class A1 {

  • 0

Lets say we have these packages and classes:

package p1;

public class A1 {
    public static void a() {}
}

package p2;

public class A1 {
    public static void a() {}
}

package p3;

import static p1.A1.a;
import static p2.A1.a;

public class A1 {
    public static void test() {

    }
}

I am wondering, why the static import of methods is legal (won’t result in compile time error) in package p3? We won’t be able to use them further in the test() method as such usage will result in the compile time error.

Why it is not the same as with a normal import of classes. Lets say we would like to import classes A1 from packages p1 and p2 into p3:

package p3;
import p1.A1;
import p2.A1;

such import is illegal and will result in the compile time error.

  • 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-13T11:06:12+00:00Added an answer on June 13, 2026 at 11:06 am

    The ambiguity of the static imports of methods could be resolved at the point of the method invocation.

    For example if you had a static import for two methods that look like this:

    void frobnicate(int i);
    // and
    void frobnicate(boolean b);
    

    Then you could import and use both, because the compiler could tell which one to use, based on the arguments you pass in (frobnicate(1) calls the first one, frobnicate(true) calls the second one).

    With classes, that’s not possible: Foobar a; alone is not sufficient to tell you which of the two Foobar classes you want.

    Also note that a single static import can import multiple names. According to the relevant section of the JLS (emphasis mine):

    A single-static-import declaration imports all accessible static members with a given simple name from a type.

    For example if the two frobnicate methods above where located in the same class, a single static import could import them both.

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

Sidebar

Related Questions

Let's say we have these two classes: public class Base { public static int
Let's say I have the following two classes: package example.model; public class Model {
Lets say I have these class public class BaseClass { public int Id {
Let's say I have these class hierarchy : public abstract class Parent { }
Lets say I have a java package commands which contains classes that all inherit
Let's say we have these checkboxes: FooCheckBox BarCheckBox BazCheckBox And these methods: Foo Bar
Let's say I have these models: class A(models.Model): name = models.CharField(max_length=32) b = models.ForeignKey(B,
What's the reason of making top-level class non-public in Java? Let's say we have
Lets say I have a class... com.mycom.app.AbstractMessage There is another class in com.mycom.model.QueryResponse QueryResponse
Let's say I have these two variables $number = 1; $word = one; and

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.