Explain System.out.println

Hi Experts,
               I know that Java.lang package is imported by all java programs. In System.out.println, System class extends java.lang and so we are able to use System, without any external imports. But out is an object of PrintWriter class (which is in java.io), please let me know how we are able to use System.out, without an import statement. I mean without importing java.io how are we able to use System.out.
 
              As per my knowledge println is a method of PrintWriter

               Please correct me if i am wrong anywhere in the question.

Thanks in advance

ramana903Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
You don't need to import PrintWriter - System imports it
0
ramana903Author Commented:
but as per my knowledge only the java.lang package is imported by default, then how is the PrintWriter class imported by default. If the PrintWriter class is imported by default then is there any other class in java.io which is imported by default.

Thanks
0
CEHJCommented:
>>then how is the PrintWriter class imported by default.

It isn't. As i just said *System* imports PrintWriter
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

CEHJCommented:
... and 'out' is a field of System
0
objectsCommented:
>               As per my knowledge println is a method of PrintWriter

It is

> then how is the PrintWriter class imported by default.

It isn't, you only need to import a class if you want to declare a *variable* of that class.
0
ramana903Author Commented:
Thanks for the information, u have mentioned that out is a field, do u mean to say that out is a variable of System?
0
objectsCommented:
correct, see the javadoc link I posted above. It shows the details of System class
0
ramana903Author Commented:
ya i have went through the javadoc. So if out is a variable how are we able to call out.println. Means a variable.method...Usually to invoke a method me use object.methodname.
0
CEHJCommented:
>>u have mentioned that out is a field, do u mean to say that out is a variable of System?

Yes
0
CEHJCommented:
>>Usually to invoke a method me use object.methodname.

'out' *is* an object
0
objectsCommented:
> So if out is a variable how are we able to call out.println. Means a variable.method...Usually to invoke a method me use object.methodname.

out is a static variable name

"System.out.println"

System = class name
out = static member variable name
println = method name
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ramana903Author Commented:
That was great, both of u have helped me to understand it. thanks a lot......:)) I am sharing the points. I had faced this question in an interview, n i had answered it but the interviewer tried to confuse me....anyway next time i will confuse the interviewer....
0
CEHJCommented:
:-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.