What is the use of - new <class name>() ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

What is the use of - new <class name>() ?

I have seen this while importing scanner class new scanner (System.in) and while creating objects

13th Aug 2017, 1:00 PM
Vaibhav Singh Sikarwar
Vaibhav Singh Sikarwar - avatar
2 Answers
+ 1
scanner is actually a class define in one of the Java library Oracle so kindly wrote for us. Unless an object or its method is static, we need to instantiate an object before we can use any of its member methods.
13th Aug 2017, 1:13 PM
Gao Xiangshuai
Gao Xiangshuai - avatar
+ 1
"New class();" calls the constructor of the class and builds an object based on that class' definition.
13th Aug 2017, 4:35 PM
josh mizzi
josh mizzi - avatar