Google+

272. System.out.println( )








System is a predefined java class in which a static object out of PrintStream I/O Class is created as shown below -

public class System
{
    static PrintStream out = new PrintStream(//constructor connected to standard output stream);
}

public class PrintStream
{
    //Code for print( ) and println( ) methods etc. 
}

As out is the static object inside System Class, hence we can access the out object from other Classes by using its Class name

 i.e. System.out

And as print( ) and println( ) method are the members of the PrintStream Class, we can access it using its object called out as shown below -

System.out.print("Text to be printed here");
System.out.println("Text to be printed here");

So, we have now understood how a System.out.println(" "); statement works. Please find the example program which uses System.out.println(" "); statement as shown below -

Example -

public class ClassName
{
      public static void main(String args[])
      {
              System.out.println("Hi. How are you?");
      }

}

Output -

Hi. How are you?






Please comment below to feedback or ask questions.

static import will be explained in the next post.










No comments: