public class ID
{
public static void main(String... args)
{
Object [] object = new String[5][5];
int counter=0;
for (Object o : object )
{
counter++;
}
System.out.println(counter);
}
}
this code outputs 5 ...
I am not getting why ...
can anyone explain ??? please ..
Head First Java has beautifully explained this Array concept. I would recommend you to read that book if you have a copy of it. Its worth reading for a beginner.
Could someone please tell me what exactly is going on behind the scenes. I understand that a two dimensional string array is created and the reference value of that 2-D array is given to a one dimensional Object array reference.
But how is it possible? By that rule the following line of code should compileBut it doesn't. Is it because in Java every Array is an Object? Can anyone shed more light on this?
int[][] a = {{1,2},{0,1,2},{-1,0,2}}; // 1
Object[] obj = (Object[])a.clone(); // 2
int [] obj1 = (int[])a.clone(); //3
The line 1 and 2 compiles fine. If I add line-3, it does not run. Can anyone explain me why?
Don't get me started about those stupid light bulbs.