-2
    Example-1
        //called
        void display(int x[])
        {    
            
            for(int i=0;i<=2;i++)
                System.out.println(x[i]);   
        }
        public static void main(String args[])
        {   
            int a[]= {1,2,3};
            Demo ob=new Demo();
            //calling
            ob.display(a);
        

Example-2    
    
int a[] = {1,2,3,4,5};
int l = a.length;

In example -1, while calling we have written array a without dimension but during called we have passed it to a parameter x[] with dimension that is an array type.even In example 2 during calculating length of an array we calculate the length without dimension just with . operator along with length property so shouldn't we use here a along with dimension like a[] during calling we have to pass it to an array type variable. as well as during calculating length a[].length

Manjeet Singh
  • 57
  • 1
  • 6
  • Qbrute. i understood, what you wants to say that. Please tell me one thing.look at my code and tell me how a[] array elements are changing with changing in x[ ] array? – Manjeet Singh Nov 07 '20 at 18:42
  • if you would use syntax of `int[] a` there would not be confusion i guess – Antoniossss Nov 08 '20 at 12:27

1 Answers1

0

Its simmple. a is a car, display is a carwash, and x is car during the cleaning.

You drive your car trough carwash and it gets clean afterwards. But it is still the same car - only modified somehow.

The same occures here - you pass array, you modify that array (its elements) and it stays modified.

Antoniossss
  • 31,590
  • 6
  • 57
  • 99