Hi Ankith suresh
you can always do
Object o = 1;
this will compile fine but if you try and print the value of o you will find an exception at run time
"Exception in
thread "main" java.lang.Error: Unresolved compilation problem:
Type mismatch: cannot convert from int to Object
"
when you try and create an array of a variable of type Object it has to be of either same class or it's subclass which is not the case in int
but when you say
Object o = new int[10];
it creates it's reference
cause
if you try this piece of code
This code will print true.
so that means when an array is created it is by default of type object only
but when you declare a variable of type object you have to initialize it with either it's sub class or object itself