Studyon Minte9.com
Head First (Java)




Arrays



		// int[] nums = new int[2];
		// Dog[] dogs = new Dogs[2];


Arrays are always objects. The array object can have elements which are primitives but the array itself is 
never a primitive. Regardless of what the array holds, the array itself is always an object.

	int[] nums; 
		// declare an int array variable
	nums = new int[3]; 
		// create a new int array with length 3
		// assign it to the nums
	nums[0] = 1;
	nums[1] = 2;
	nums[2] = 3;
		// Give each element in the array an int value
		// Remember, elements in on int array are just int variables.

	%java

	    public static void main(String[] args) {
		
		int[] nums;
		nums = new int[3];
		nums[0] = 1;
		nums[1] = 2;
		nums[2] = 3;
		nums[3] = "abc";  // Compile Error
	    }

	%java

		public class TestingApp {
		    
		    public static void main(String[] args) {
			
			Dog[] dogs = new Dog[4];
				// we don't create a new Dog object
				// we create an Array by Dog types values

			dogs[0] = new Dog();
			dogs[1] = 2; // Compiler Error 
		    }
		}

		class Dog {
		}