+ 1
Difference between array definition and declaration?
3 odpowiedzi
+ 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');
  };
};
+ 8
For an array:
    int[] myArray;  // declaration
    myArray = new int[]{1, 2, 3}; // definition
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.





