java - Assign subclasses to each array element (run-time type) -
i have base class building , subclasses house , school. have declared array of building objects following way. not sure how assign subclasses each array element (run time type).
building[] house = new building[3]; building[] school = new school[2];
you can use instanceof determine subclass
if (building instanceof house) { house[0] = building; }
Comments
Post a Comment