Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the type of System.out in Java?

I am just a newbie in Java. I was wondering the way System.out.println() is used. Out is a static field inside System class. The type of out is PrintStream. But when I saw the constructor of PrintStream class, it takes a parameter of type OutputStream and as far as I know we cannot create the object of an abstract class. In that case we must pass some subclass's object to the constructor of PrintStream. What is that class? Same is the System.in. It is also InputStream's reference but what is the type of object it points to as the InputStream is abstract?

like image 579
abhithakur88 Avatar asked Jan 21 '13 08:01

abhithakur88


People also ask

What type of object is System out?

System. out is a member of System and it is of type PrintStream.

What is Sustem in in Java?

System.in in java means to take input from the keyboard or user. System. out in java means to print the output to console.


2 Answers

PrintStream wraps BufferedOutputStream, which wraps FileOutputStream, which is writing into the console, which has its own FileDescriptor.

like image 127
Andremoniy Avatar answered Nov 07 '22 16:11

Andremoniy


A simple way to view the structure of a class is to examine it in a debugger.

As you can see @Andremonify's description is basically what you have.

FileDescriptor

  • 0 is System.in
  • 1 is System.out
  • 2 is System.err
  • 3+ is used for other files

enter image description here

like image 36
Peter Lawrey Avatar answered Nov 07 '22 16:11

Peter Lawrey