+ 3
What is the difference between these two?
Class c; Class c=new Class() ;
2 Answers
+ 3
First one has no value (null).
Second one has a value in device memory.
"new" keyword means a "new space" on device memory.
Obs.: you can't use null values once you catch the NPE (NullPointerException).
+ 2
They are similar.
First isn't initialized and second is Initialized.
Class c;
c is not initialized and would be null.
So trying to use any of the functions in the Class Object on c would not compile.
If later in the project you do: c = new Class()
This would save space in memory as to only initialize it later when you need it. This would only make sence to me if c was a global variable.
Then you can use the functions inside the Class Object: c.Function();
Class c = new Class()
c is initialized to be a Class Object.
You could then use the functions inside the Class Object: c.Function();