1. Declaring a variable
Variable has a type and a name
Primitive variable and reference variable
2. Array
declare:
int[] nums;
create a new int array:
nums = new int[7];
arrays are objects too.
3.Exercise
A. We should create new Books objects after we create a new Books array.
class BooksTestDrive{
public static void main(String[] args){
Books[] myBooks = new Books[3];
int x = 0;
while (x < 3){
myBooks[x] = new Books();
x = x + 1;
}
myBooks[0].title = "A";
myBooks[1].title = "B";
myBooks[2].title = "C";
myBooks[0].author= "a";
myBooks[1].author= "b";
myBooks[2].author= "c";
x = 0;
while (x < 3){
System.out.println(myBooks[x].title + " by " + myBooks[x].author);
x = x + 1;
}
}
}