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

后端 未结 6 1537
心在旅途
心在旅途 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:40

    array is an collection of objects or collection of primitive datatypes while string is a sequence of characters. as you know object is super class of every other class that's why you an do like below: Object c = new Object[] {1,2,"22" };

    String class is not super class of array type...so you can't perform like below..

    String s = new String[]{"s","s"};
    

    hope this will help you...

提交回复
热议问题