+ 1
"scanner myvar = new" is new a value here? Like saying this is empty for now?
3 Antworten
+ 6
new is a keyword, not a value.
new is used to create an instance of a class (object).
+ 6
Scanner scnr = new Scanner();
From what I can tell, your declaration is simply incomplete. The statement I posted above is how you would go about declaring a scanner object. The "new Scanner()" part of it lets it know to instantiate a new object from the scanner class. In my example, we're storing a reference to that new object in the "scnr" variable so we can use it.
0
Scanner obj=new Scanner(System.in);
Scanner is the class whose object is to be created, 'new' is the keyword which creates the object named 'obj'