-1
  1. System.class contains "out" and "err" object of Printstream class.
  2. System.class is declared static.
  3. println() is a overloaded method in Printstream class which have (out and err objects)

if we execute System.out.println("Xys"); and System.err.println("Fdfd");

They both should work Exactly the same as out and err are the objects of the same class except for the fact that they don't.

Why out.println() prints in black and err.println() prints in red.

4

1 回答 1

6

因为您使用的 IDE 以红色打印 stderr,以黑色打印 stdout。

这与 Java 无关,而与您所处的环境有关——这是在进行着色,而不是 Java 本身,它并不关心其输出的实际呈现方式。

于 2014-09-10T13:16:25.260 回答