class Book {
String name;
String author;
}
class BookTest {
public static void main(String[] args) {
Book[] books = new Book[2];
books[0].name = "The graps";
books[0].author = "Siffyu";
books[1].name = "Nova supreme";
books[1].author = "Jagga";
for (int i = 0; i < books.length; i++) {
System.out.println(books[i].name + ": " + books[i].author);
}
}
}
I tried creating an array that can hold Book type object. Once I created the array, I then initialized the book objects inside the array and tried to print them. I got NullPointerException instead.