Lets say I have this:

Code:
class classX
{
int name;
int age;
}

class classY
{
classX obj;
}
If I were to declare "classY y", and then put "y.name" as a parameter, it will crash because "y' was not initiated. Is there a way so that it does not crash? I know I could use "try...catch", but it could get messy and too many codes may have to be written. For instance, I would have to first check to see that "y" is not null, then use y.name as a parameter. But what happens if its like this:

class classA
{
int property1;
}
class classB
{
classA obja;
}
class classC
{
classB objb;
}
class classD
{
classC objc;
}

And "classD d" is declared, and I want to use "d.objc.objb.obja.property". I would have to make sure that each layer of class is initiated so that when i use "d.objc.objb.obja.property", it does not crash. Now is there a way or nice algorithm so that I won't have to check each class if they are initiated.