Question: Consider the code: public class Book { private String title; private String author; public Book ( String title, String author ) { this.title = title;

Consider the code:
public class Book {
private String title;
private String author;
public Book(String title, String author){
this.title = title;
this.author = author;
}
public void printBookDetails(){
System.out.println("Title: "+ title +", Author: "+ author);
}
public void saveToDatabase(){
// Code to save the book details to a database
}
}
Which modification adheres to the Single Responsibility Principle?
Question 1Answer
a.
Move printBookDetails() method into a BookPrinter class
b.
Combine the printBookDetails() and saveToDatabase() methods into one
c.
Add another method to handle the saving and printing functionality in a single call
d.
The class already obeys Single Responsibility Principle, no change is needed

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!