0
Please explain new class() and Class obj = new class();
What is the exact difference between these two
2 ответов
+ 4
The only difference is that you are holding the reference to the object in the 2nd case and not in the 1st one. I do not think there is a performance difference between the two.
Scanner sc = new Scanner(new File("filename"));
In the above case you need not create a reference to the file object. There could be other similar scenarios.
It's totally up to a programmer to manage them according to their use in the code.