Java - array of different objects that have the same method(s)

前端 未结 4 1058
一生所求
一生所求 2020-12-17 05:57

I am practicing inheritance.

I have two similar classes that I\'d like to assimilate into one array, so I thought to use the Object class as a superclass since ever

4条回答
  •  醉梦人生
    2020-12-17 06:39

    Object doesn't have the method beingShot. If all of the objects in array are of the same class, then your array should be of that same class. Otherwise they all should have same interface implemented or extend the same class. I can't imagine why would you want explicitly extend Object here, it doesn't add any functionality whatsoever.

提交回复
热议问题