title: Java Basics - Instantiation of objects
body: <p>I was learning Java and came across this code snippet. Have an answer for that but I am not exactly understanding how it works.</p>
  
  <p>I have a class Books</p>
  
  <pre><code>class Books {
     String author;
     String title;
  }
  </code></pre>
  
  <p>Then I have test class</p>
  
  <pre><code>class TestForBook {
  
     Books[] myBooks = new Books[3]; // doubt : 1
     System.out.println('myBooks length is ::' + myBooks.length);//prints 3. Its correct.
  
    myBooks[0].title = 'Book1 title'; // This throws null pointer exception
  
    myBooks[0] = new Books();
    myBooks[0].title = 'Book1 title'; //works fine after above line
  }
  </code></pre>
  
  <p>I want to understand why even after declaring array of type Books, array values have null(doubt : 1 in comments, I am referring to that line).</p>
  
  <p>I do not know what concept of Java I am missing. And how/from where I can learn these kind of topics. Any resource or books suggestion also would be appreciable. Thanks.</p>
  
  <p>It is not duplicate of question id : 1922677. Solution is available there(I have also given the solution) but I wanted to know why it is like that. I mean even after declaring, why it has null was my question.</p>