Difference between array definition and declaration? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Difference between array definition and declaration?

3rd Mar 2017, 2:11 PM
Shah faisal khan
Shah faisal khan - avatar
3 Answers
+ 8
Have a look at this example with an abstract class... Declaration means you just tell the compiler that there is a class, variable or method, but not what it is doing. Just like a template. To actually 'use' a class, method, variable you have to tell the compiler what it is supposed to do by defining them. Example: // ** declaration // class abstract class myClass { // variable int i; // method abstract void doSomething(){}; }; // ** definition // class public class myDerivedClass extends myClass{ // variable int x =1; // method @Override void doSomething (){ System.out.print ('method body defines what this method is supposed to do'); }; };
3rd Mar 2017, 4:27 PM
Tashi N
Tashi N - avatar
+ 8
For an array: int[] myArray; // declaration myArray = new int[]{1, 2, 3}; // definition
3rd Mar 2017, 4:32 PM
Tashi N
Tashi N - avatar
0
array definition ..it is all about creating a reference variable..but when you declare it ..you are asigning(alocating) a memory location and size of your array.
3rd Mar 2017, 2:26 PM
ibrahim selman