explain System.out.println

Answer Posted / anil kumar

System is a final class in java.lang package

println() is a method define in PrintStream class of
java.io package.
the Printstream class like as

Class PrintStream
{
public void print()
{..........}
public void println(String a)
{...........}

..
..
..

}
and the System class like as

class System
{
public static void PrintStream out;

..
..
out=new PrintStream();
}

this is clear that System is a class and println is a
method but what is out.

out is a reference variable of PrintStream Type that hold
the object of printstream class;
out is a static type so it can be call with its class name
so we can access out with System.out and then we can call
println method on this out object
System.out.println();

now why sunmicrosystem do this
because we haveto not create a new object of Printstream
class for each time when we call println mehod
now we can call println method with the help of precreated
object of printStream class

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What design pattern you have used in your project? I answered Factory pattern, how it is implemented? What are its advantage? Do know about Abstract Factory?

1940


Why is it called buffering?

585


What is bitwise complement?

502


Explain the difference between treeset and treemap in java?

532


What is boolean example?

529






What is module in oop?

571


What is getkey () in java?

578


What is the base class of all classes?

571


How do you control extraneous variables?

506


Can subclass overriding method declare an exception if parent class method doesn't throw an exception?

508


Why are arrays useful in java?

544


What is a prefix function.write down a code to compute prefix function.

542


Does variable declaration allocate memory?

587


Why object class is super class for every class in java?

578


How can you avoid serialization in child class if the base class is implementing the serializable interface?

640