What is system.in

前端 未结 9 1270
隐瞒了意图╮
隐瞒了意图╮ 2021-02-06 05:50

Consider this Scanner input example.

Scanner user_input = new Scanner( System.in );

Here Scanner is the CLASS.

9条回答
  •  没有蜡笔的小新
    2021-02-06 06:27

    Scanner class has a constructor Scanner(InputStream) in its profile i.e when we call Scanner() constructor during the object creation time it will let you to pass the object of InputStream class.

    "in" is an object of "InputStream" class defined in System class(like "out" is an object of PrintStream class defined in System class).

    Thus System.in is nothing but calling the "in" object of InputStream class defined in System class when Scanner constructor is called during object creation time.

    Scanner(InputStream) is pre-defined constructor in Scanner class which when calls requires the object of InputStream class as the parameter and that object is System.in.

提交回复
热议问题