Hi,
2 things....
I need to know the reason to this. I'm swatting up for this
test as well...
Am I right in saying that the reason it works is because the declaration/initialisation statement;
int j[][]={{ 12,12,34,56,76,34,78,78}, { 12,12} };
causes (in effect) an array of Array objects to be created. Thus we have one array (of array objects).
the following line works;
Object obj[] = j;
because we are assigning an array of array objects (j) into an array of objects (obj).
PLEASE tell me thats right!
ASIDE and completely unrelated. Everything... all java classes inherit from the base class Object, yes. I mean EVERYTHING (except primitive types). yes?
Have a nice day.
GrahamO
Originally posted by Sandeeep Vaid:
Hey,
Good question.
I think it will work as we are assigning an object only...
Definitely it will compile and run....
package temp;
class Temp
{
public static void main(String args[])
{
int j[][]={
{ 12,12,34,56,76,34,78,78},
{ 12,12}
};
Object obj[] = j;
for(int i=0;i<obj.length;i++)
System.out.println(obj[i]);
}
}