• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Details of "System.out.println"

 
Soumya Ghosh
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Can any one please explain individual of "System.out.println" ?

According to my thinking, System is a class. out is its object and println is the method called by out for printing some thing.
But, I think out belongs to printWriter object.

So, I am getting confused. Please help me.
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You almost have it. out is a reference to a Printwriter class and you can use this reference to access the Printwriter API from the System class. println() is a static method so you dont need an instance an object to reach this method. Is there any other confusion ?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
System is a class.

out is a public static variable of that class, it is of the type PrintStream

println is a method of the PrintStream class.

Basically, you could think of the System class being coded like this (its not, but hopefully you've seen code like this before an it will give you the idea):

[ April 23, 2007: Message edited by: Paul Sturrock ]
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Paul Sturrock:
System is a class.

out is a public static variable of that class, it is of the type PrintStream

println is a method of the PrintStream class.

Basically, you could think of the System class being coded like this (its not, but hopefully you've seen code like this before an it will give you the idea):


[ April 23, 2007: Message edited by: Paul Sturrock ]


Yikes ! I meant to say PrintStream.
 
prasad valeti
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here i'm writing one example where System class ,out object & println() method are explained

class A{

static B b;

}
class B{
void example(){
System.out.println("prasad");
}
}
class C{
public static void main(String s[]){
A a = new A();
a.b.example();
}
}
output:
prasad.

A-------->System class
b--------->out is a static variable of type PrintStream
B.........>PrintStream class
example()..........>println()
 
umamahesh javvadi
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
small Modification of A,B,C example
This code works ... check it and run

class A{//Assume this as System class
static B b1=new B();//create an object of B(assume B as PrintStream)
//create a final static variable(assume it as out varaible)
final static B b=b1;
}
class B{
public void example(){
System.out.println("mahesh");

}
}
class C {
public static void main(String as[]){
//A(System class).b(out of PrintStream //class).example()(println() in //PrintStream class
A.b.example();
}
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic