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
Somewhat confusingly, an Object[]
is an Object
. (For one thing this is how Java can implement zero-length arrays, and allow arrays to be function return values).
So assigning an Object[]
instance to a reference of type Object
type makes sense.
But assigning a String[]
instance to a reference of type String
does not make sense. (But note that String[]
is also an Object
.)
So
Object c = new Object[] {1,2,"22" };
Makes senseString s = new String[]{"s","s"};
Doesn't make senseObject s = new String[]{"s","s"};
Makes sense