Author Topic:   System.out - a static handle
gunjan
ranch hand
posted April 13, 2000 10:17 PM         
Friends:
System.out is a static reference to the PrintStream class. PrintStream class has println methods which are non static. That is System.out.println("test");
println is a non static method of class PrintStream.

My question is that can one invoke a non static method using a static reference, without the instance not even existing

Any help appreciated.
Also look at other post on read method.

Thanks in advance
Gunjan

maha anna
bartender
posted April 14, 2000 12:29 AM             
gunjan,
System.out is a static member of the class System . Which means the static member 'out' can't access any instance members of the class in which it is defined, which here is the 'System' class.
Also note that the static member var 'out' is a reference to another PrintStream instance. Through a reference we can access both static and instance member var/methods. This is what happens here. So the .out in System class CANNOT access any instance member / instance methods of the 'System' class. Being a reference to another PrintStream instance, and the println(..) method is defiend as instance method in PrintStream class, the out variable in System class can very well invoke this println method.

I leave your another related qstn to others.
regds
maha anna

|