0

Please explain new class() and Class obj = new class();

What is the exact difference between these two

1st Jul 2020, 6:00 PM
Abhishek Tak
Abhishek Tak - avatar
1 Antwort
+ 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.
1st Jul 2020, 6:14 PM
Avinesh
Avinesh - avatar