ArrayList containing different objects of the same superclass - how to access method of a subclass

前端 未结 4 1533
伪装坚强ぢ
伪装坚强ぢ 2021-01-18 09:51

Hi I\'m wondering if there is a simple solution to my problem,

I have an ArrayList:

ArrayList  animalList = new          


        
4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-18 10:50

    Bird getMyBird(Integer aniInteger) {
            Bird b = new Bird();
            //Do somthig with bird object...
    
            return b;
            //get your modifeid bird object
        }
    
        Bird myBird = animalList.get(animalIndex);
    
        myBird.move();
    

提交回复
热议问题