java

profileMajdM
java.docx

Giving the following code snippet:

Discuss the reasons of using private access specifier in some places of the code and public in other places. Additionally, discuss how can you test this code.

 

public class Book

{

      private String bookName;

      private int ed;

      private String author;

     

      public Book (String n, int e, String a)

      {

           bookName = n;

           ed = e;

           author = a;

      }

     

      /**

       * Gets the book name.

       * @return the book name.

       */

      public String getBookName()

      {

           return bookName;

      }

     

      /**

       * Gets the book edition.

       * @return the book edition.

       */

      public int getBookEd()

      {

           return ed;

      }

     

      /**

       * Gets the book author.

       * @return the book author.

       */

      public String getAuthor()

      {

           return author;

      }

 

          

      /**

       * Prints the Book details.

       */

      public void printBookDetails()

      {

           System.out.println("Book Name:" + getBookName() );

           System.out.println("Book edition: " +  getBookEd() );

           System.out.println("Book Author: " + getAuthor() );

      }

}