java arrays with objects and refernce -


Hello I have a basic doubt, when I was doing the analysis of the object and reference.

  int a; // Here we are making an object an integer integer integer b = new integer (); // Here we are creating a reference variable b, in the object type opener in heap.   

What is the benefit of each one? Where in the case of Array "int a" and second one ??

,

  int [] a = new int [5];   

If "int a" is possible, then "int a [5]" is not possible because the code faucet indicator throws the exception,

  Int one [5]; A [0] = 10; Println (a [0]); // zero indicator gives exception   

The code works fine

  int [] a = new int [5]; A [0] = 5; Println (a [0]);   

If there is a case in which "int a" works in the case before leaving it, then what should be made?

int one is declaring a primitive variable, which is A , that type is not int are not objects, but arrays are primitives objects.

There are tabular objects, but they are a special type of object that has special syntax for use in Java when you are using int [] a An object is declaring, which is called a , which is an array of ints when you provide it with the a = new int [5] So it seems that you are calling a constructor in a special way. It seems that you were actually calling some constructors and passing the shape as a parameter: A = new intent (5) or some other Java gives you special syntax so that No need to build.

Similarly, when you call a [0] = 5 , on your object a as you are calling a method, But Java gives you special syntax for it, it is almost as if you are calling a.setValue (0, 5) , but Java gives good syntax so that this type of thing is not even needed.

So if you declare int a [5] , which tried to declare a variable using the new intent (5) It would be ... which is not understood as a variable declaration. You will basically use a call to the constructor to declare a variable, which will not understand much.

Comments