import java.io.*;
 class WriteFile
{

public static void main(String ss[])
{

    try
    {

        FileWriter fw=new FileWriter("output.txt");
        PrintWriter pw=new PrintWriter(fw);
        String s1="Hello World";
        String s2="I Am Learning Java";
        pw.println(s1);
        pw.println(s2);
        pw.flush();
        pw.close();
        fw.close();
    }
    catch(IOException e)
    {

        System.out.println(e);
    }
}
}

in upper code println() is called with object of PrintWriter and confusion is that println() is the method of PrintStream how it is possible to call a method of a class with object of another class please clarify it

PrintWriter and PrintStream both implement a println method. Read their API doc for details.

ps: Your last three posts are still not "Solved". What's the problem?

Edited 2 Years Ago by JamesCherrill

How about using Google with keywords - java doc api PrintWriter - instead of asking someone else to do it for you?

Edited 2 Years Ago by Taywin

@moaz, you might want to learn to be polite to people. It often helps to get help from them...
You might also learn to think for yourself, it helps you not need to ask for help so often.

And of course you might learn to search for information yourself, helps a lot too.
You can download the API docs (or reference them online) from the same place you can download the JDK...

if i am asking some question from you then you have to help me but you are not help me as you like what can i say.

Comments
we HAVE to help you? wel excuse me, your Highness.

if i am asking some question from you then you have to help me but you are not help me as you like what can i say.

Excuse me, who are you to me? Are you a person who can determine my life? The way you use English is extremely rude in English native speaking culture. Your question is rude, and your reply is even worse. Your reply indicates that people on this site must serve you when you ask a question. This is unacceptable. Everyone here is a volunteer and does not ask for anything back from others.

We do because we would not mind sharing our knowledge. If you want someone to answer your questions without you lifting a finger, hire the person and stop using public forums.

In spite of the tone of your responses, I'll give you some help anyway.

The answer is that there is no relationship between the PrintWriter.println(String) method and the PrintStream.println(String) method. Yes, they look the same. Yes, you could change from one class to the other, and the calls would all still work. But technically, in Java, there is no relationship between these two "println" methods. They just happen to look the same and to do essentially the same thing.

You could determine this by looking at these two JavaDoc pages:
http://docs.oracle.com/javase/7/docs/api/java/io/PrintWriter.html#println(java.lang.String)
and
http://docs.oracle.com/javase/7/docs/api/java/io/PrintStream.html#println(java.lang.String)

After noticing that the descriptions of the two methods are essentially the same, scroll up to the top of both pages and notice that they have no parent classes in common (except for java.lang.Object, which does not define this method).

So there is no real technical issue involed here. It's only a matter of convention and expectations.

This question has already been answered. Start a new discussion instead.