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

后端 未结 6 1523
心在旅途
心在旅途 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 12:50

    First, array holds the reference of values which are in heap.

    Second, Object class is mother class of every other class in java. so object array can hold any kind of reference value but string array will only hold reference of string data type and each and every reference is referring to separate string (string[0]= "a",string[1]="stackOverFlow"...).

    Third, A string is a sequence of character in java.

    so, a sting array can not be a string because it is not referring to sequence of characters but referring to string type of objects residing in heap.

提交回复
热议问题