Difference in initialilizing a class in difference ways


  • Suppose i have a class "TEST" What is the difference between

    TEST obj = new TEST();


    TEST obj = null;


    Wednesday, July 17, 2013 10:49 AM


  • TEST obj = null;  -- means that the object is set to nothing or null reference. when trying to accees ,the object initialized as TEST obj = null; will throw  a nullreferenceexception.

    TEST obj = new TEST(); -- indicates a valid initialization, obj helds reference to type test.i.e some memory has been allocated by the .net framework for it.

    • Marked as answer by Rohit Binjola Wednesday, July 17, 2013 11:16 AM
    Wednesday, July 17, 2013 11:01 AM