If an array of Object is an Object, why is an array of String not a String

后端 未结 6 1375
心在旅途
心在旅途 2021-02-15 12:06

Object class is super class to every class in Java. So every class should inherent the properties or behavior of Object class.

Then we can declare array of objects as sh

6条回答
  •  感动是毒
    2021-02-15 13:04

    Its basic Java principle, Everything is an Object, thus you can use Object reference for everything like Object o = new AnyOtherClass()

    You can use reference of a class for its sub classes like List l = new Arraylist()

    But String[] is an Array and Array is not an ancestor of String

提交回复
热议问题