Google News
logo
Java - Interview Questions
There are two array objects of int type. one is containing 100 elements and another one is containing 10 elements. Can you assign array of 100 elements to an array of 10 elements?
Yes, you can assign array of 100 elements to an array of 10 elements provided they should be of same type. While assigning, compiler checks only type of the array not the size.

public class MainClass
{
    public static void main(String[] args)
    {
        int[] a = new int[10];
        int[] b = new int[100];
        a = b;      //Compiler checks only type, not the size
    }
}
Advertisement