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
Object c = new Object[] {1,2,"22" };
is valid due to the fact that an array of Object
s is still an Object
. You could specify that c
is an array of Object
s at declaration level too, like this:
Object[] c = new Object[] {1,2,"22" };
However,
String s = new String[]{"s","s"};
is not valid, since an array of String
s is not a String
. You need either to convert your array into a String
, like this:
String s = String.join(",", new String[]{"s","s"});
or to store it as an array, like this:
String[] s = new String[]{"s","s"};