-2

Why is "out" variable in System class of java.lang package "static" in JAVA? I Know that System is a static class and println() in PrintStream Class is not a static method. What is the relation in between these two?

Learnee
  • 101
  • 1
  • 9
  • it is static, so you wouldn't need to instantiate System in order to call it. Can you imagine the horror of having to create an instance of System in each class you want to use System.out.print(ln)()? – Stultuske Mar 23 '18 at 14:36
  • `System` is a class. So if you want to access `System.out` directly, it needs to be a static field. – khelwood Mar 23 '18 at 14:42
  • An example of it wasn't static would go something like this - 'System sys = new System(); sys.out.println("This is frustrating"); – Sean Mar 23 '18 at 14:48
  • Thank you. I am having this kind of silly doubts from the last few days. I am just a beginner to OOP concepts and JAVA started 4 days back. Thanks for your time for replying to this doubt. – Learnee Mar 26 '18 at 05:03

1 Answers1

0

That is because static variables can be used without instantiating the class. So, something as simple as printing for which you use out mostly you don't have to create an instance of System class and can access the variable with just class name.

humblefoolish
  • 409
  • 3
  • 15