+ 2

What happened when we declared class obj??

Let's consider player is defined. Now we declare Player mario ; What will happen if we don't declare Player mario = new player (); Someone please explain.

2nd Dec 2017, 1:07 PM
Md Shahabuddin Hossain
Md Shahabuddin Hossain - avatar
2 Réponses
+ 4
I am not sure, but I think a new section or amount of memory is needed to store an object.And the new keyword allocates that memory for the object.
2nd Dec 2017, 2:13 PM
Md. Nafis Ul Haque Shifat
Md. Nafis Ul Haque Shifat - avatar
+ 1
I mean, you can just try it. It throws an error. https://code.sololearn.com/cVkPYU5vjhEg/?ref=app You can't use an object if you have never made one, the variable itself is just a placeholder until you assign an object to it.
2nd Dec 2017, 1:32 PM
Schindlabua
Schindlabua - avatar