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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:15:07+00:00 2026-05-21T09:15:07+00:00

import static java.lang.System.out; import java.io.FileNotFoundException; import java.io.PrintWriter; public class ShadowingByImporting { public static void

  • 0
import static java.lang.System.out;  
import java.io.FileNotFoundException;
import java.io.PrintWriter;

public class ShadowingByImporting
{
    public static void main(String[] args)throws FileNotFoundException
    {
       out.println("Calling println() in java.lang.System.out");
       PrintWriter pw=new PrintWriter("log.txt");
       writeInfo(pw);
       pw.flush();
       pw.close();
     }

    public static void writeInfo(PrintWriter out)    
    {
      out.println("Calling pritnln() in the parameter out");
      System.out.println("Calling println() in java.lang.System.out Example");
    }  
}

The above program is given in Khalid Mugal’s SCJP Guide,according to him by the principle of shadowing in static import the second println method in writeInfo. Method will execute twice, but when I run this following dissimilar output came.

Please somebody explain what’s the actual concept.

Calling println() in java.lang.System.out

Calling println() in java.lang.System.out Example
  • 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-21T09:15:09+00:00Added an answer on May 21, 2026 at 9:15 am

    This has nothing to do with static imports in general,
    but rather with the fact that the parameter out of writeInfo is hiding the outer definition of out which in this case happens to be a static import.

    This hiding is also possible when you have

    public class ShadowingByImporting
    {
        PrintWriter out = ...;
        public static void main(String[] args)throws FileNotFoundException
        {
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the code: import java.lang.*; import java.io.*; class string { public static void
This is my java file : import java.io.File; import java.lang.String; public class ListFiles {
I got the following code: import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Sha1{ private static
When used like this: import static com.showboy.Myclass; public class Anotherclass{} what's the difference between
trying to overload the java.lang.Math.sqrt static method for int type : import static java.lang.Math.sqrt;
I'm new to Java. I wrote the following code: import java.io.*; import java.lang.*; public
Code : import java.io.*; class Customer { String name; int ID; int purchasequantity; double
Possible Duplicate: Causes of 'java.lang.NoSuchMethodError: main Exception in thread “main”' I am using Eclipse.
This is the complete code : import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.lang.Thread;
As the title suggests, is it correct or valid to import/export static data from

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.