ExamVeda
Login
Home
This question belongs to Java Program Array
Array
?

Determine output:
public class Test{
        public static void main(String[] args){
                int[] x = {1, 2, 3, 4};
                int[] y = x;

                x = new int[2];

                for(int i = 0; i < x.length; i++)
                        System.out.print(y[i] + " ");
        }
}

Answer & Solution
Correct Answer: Option C
Let's discuss the solution. Join the discussion
Examveda
Question posted by Examveda
Community

Join the Discussion

2 Comments
Santhosh
Santhosh 5 years ago
previously y is initialized with x in that case y[4] and then later x is initialized with size 2 that means in for loop x.length means it size is 2 but initial value for "i" in for loop is given as zero that means it satisfies two conditions that is 0
Janitha Prabath
Janitha Prabath 10 years ago
a good explanation : http://stackoverflow.com/questions/34462460/how-does-x-new-int2-work-in-this-java-code