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

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -