Basic Programming Question

Suppose I create a class, ClassA, and have a child class, ClassB which, naturally, inherits from ClassA. Now, say I create a variable, varA, to hold a value of the type ClassA. Can I store on object of type ClassB in varA? Put another way, would the folowing code snippet work:

class ParentClass
{
   //class definition
}

class ChildClass extends ParentClass
{
   //class definition
}

var blah : ParentClass;
blah = new ChildClass();

And by ‘work’, I mean, is this valid? Would all the member data in the ChildClass object persist in the value of the variable blah?

Begin with an attempt in Unity, only when you fail or get stuck then ask the question.

While I can apreciate the “Teach a Man to Fish” ideology, your suggestion does me no good considering I don’t currently have access to a machine with Unity. I am designing, and I need the question answered to move forward with the design.

Sure, that would work.
It might not do what you want it to do though.

What, specifically, are you trying to do?

-Chilton

Creating a container object. I want it to hold several different kinds of objects, but all of which have the same parent object. Rather than use Array(), I just want to use one fixed array.

Create an array of type System.Object and cast the stuff you get out from it to the class you know it is.

Will that work for putting stuff in it, then getting it out again?