Accenture Java Programming Practice Question
Given the class Book and Library in two different packages : 1. package model; 2. public class Book { 3. private static void countBook { } 4. } 1. package util; 2. public class Library { 3. public static void main(String[] args) { 4. // insert code here 5. } 6. } What is required at line 4 in class Library to use the countBook method of Book class?Answer options
A
Not accessible – countBook is private
B
Book.countBook()
C
model.Book.countBook()
D
import model.Book; Book.countBook()
Correct answer: Not accessible – countBook is private
Explanation
The countBook method is private; it cannot be accessed from the Library class in another package.