Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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,

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

{

privateStringbookName;

privateinted;

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()

{

returnbookName;

}

/**

* Gets the book edition.

* @return the book edition.

*/

publicintgetBookEd()

{

returned;

}

/**

* 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() );

}

}

* use MS Format

* be sure of answer

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions